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; }
Comments
Post a Comment