Reverse number using while loop
import java. util. Scanner ;
class Reverse {
public static void main (String [ ] arg) {
Scanner obj = new Scanner (System.in ) ;
int n, r=0 ;
System.out.println (" Enter the no :- ") ;
int a = obj. nextInt() ;
while (a>0) {
n=a%10 ;
r=r*10+n;
a=a/10;
}
System.out.println (" Reverse number " + r);
}
}
0 comments:
Post a Comment