1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Rever{ public static void main(String args[]){ int num = 4894895; int reverse = 0; while(num != 0){ int remainder = num %10; num /=10; reverse = (reverse*10) + remainder; } System.out.println(reverse); } } |
Output
5984984
Discussion
For ‘for’ loop use – for(;num!=0;)
Compiled with JDK 9