Java program to reverse a number is one of the simplest programming problems. The JAVA program that reverses a number is given.
package MathUtility; class ReverseNumber { int reverse(int num) { int rev=0, rem; while(num>0) { rem = num % 10; rev = (rev*10)+ rem; num=num/10; } return rev; } public static void main(String args[]) { if(args.length==0) System.out.println("No Input provided"); else { int num = Integer.parseInt(args[0]); ReverseNumber rn = new ReverseNumber(); System.out.println("Reverse of the number " + num + " is " + rn.reverse(num)); } } }To compile the program
javac -d . ReverseNumber.javaTo run the program
java MathUtility.ReverseNumber 1115001
No comments:
Post a Comment