Wednesday, 25 November 2015

How to reverse a number in java

package com.javaproficiency;

public class ReverseNumber {

public static void main(String[] args) {
int num =251;
int rNum =0;
while(num > 0){
rNum = rNum*10+ num%10;
num = num/10;
}
System.out.println(" reverse number is ="+rNum);
}
}


Output:

 reverse number is =152

No comments:

Post a Comment