Tech Study

Write a Java program to reverse an integer number

Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..

public class Javamathexcercise {
   public static void main(String[] args) {
    int number =123456789;   
    int is_positive = 1;
        if (number < 0) {
            is_positive = -1;
            number = -1 * number;
        }
        int sum  = 0;
        while (number > 0) {
            int r = number % 10;
 
            int maxDiff = Integer.MAX_VALUE - sum * 10;
            if (sum > Integer.MAX_VALUE / 10 || r > maxDiff) 
                System.out.println("wrong number");;
 
            sum = sum * 10 + r;
            number /= 10;
        }
        System.out.println(is_positive * sum);
   }
}

Result

Write a Java program to reverse an integer number
Write a Java program to reverse an integer number

TaggedWrite a Java program to reverse an integer number

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more