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

Leave a Reply

Your email address will not be published. Required fields are marked *

82 − 75 =