Java Code to Reverse a Number

Reverse a Number using Java


Java


import java.util.Scanner; 

class ReverseNumber { 
public static void main(String args[]) { 

int num=0; 
int revnum =0; 

System.out.println("Input your number and press enter: "); 

Scanner in = new Scanner(System.in); 
num = in.nextInt(); 

while( num != 0 ) { 
revnum = revnum * 10; 
revnum = revnum + num%10; 
num = num/10; } 

System.out.println("Reverse of input number is: "+revnum);
} }




Click here to run this code



More Free Code Examples:


Java Code to Reverse a String


Java Current Time and Date Program


Javascript Easy Battleship Game






Comments

Popular posts from this blog

Crypto Mining

Multi-tap Keypad Text Entry