Reverse of number (Armstrong Program)
Reverse of number means reverse the position of all digits of any
number. For example reverse of 839 is 938.
Example
import java.util.Scanner;
class Reverse
{
public static void main(String[] args)
{
int no,rev=0,r,a;
Scanner s=new Scanner(System.in);
System.out.println("Enter any number:
");
no=s.nextInt();
a=no;
while(no>0)
{
r=no%10;
rev=rev*10+r;
no=no/10;
}
System.out.println("Reverse: "+rev);
}
}
Output
Enter any
number :
153
not Armstrong
Syntax to compile and run
java program
Syntax
for compile
-> c:/>javac Reverse.java
for run ->
c:/>java Reverse
Explnation of Code
·
Scanner
s=new Scanner(System.in): are used for receive input from keyboard.
·
nextInt(): method
are used for get integer type value from keyboard.
·
System.out.println("....."): are used
for display message on screen or console.

0 Comments