Find the reverse of a number. eg if input number is 786 then output should be 687.
[sourcecode language="java"]
package myrnd;
public class ReverseNo {
// 786 : reverse : 687
public static void main(String[] args) {
int n = 78890;
int result = 0;
int remainder;
while (n > 0) {
remainder = n % 10;
result = result * 10 + remainder;
n = n / 10;
}
System.out.println("Result:" + result);
}
}
[/sourcecode]
No comments:
Post a Comment