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