49)
Write a program to accept a multi digit long integer number(max.
8 digits) and do the following:
1- Print the Reverse Number. (123…321(reverse))
2-Print the Absolute difference between them.
3- Print Smallest Digit. (7839== smallest
digit is 3)
import java.util.*;
public class Menu_driven_7
{
public static void main(String args[ ])
{
Scanner sc = new Scanner (System.in);
System.out.println(">>>>...MENU...<<<<");
System.out.println("Press 1 for REVERSE a number");
System.out.println("Press 2 for ABSOLUTE DIFFERENCE");
System.out.println("Press 3 for SMALLEST DIGIT of a number");
System.out.println("\nEnter yopur choice");
int c = sc.nextInt();
switch(c)
{
case 1:
System.out.println("Enter a number (not more then 8 digit)");
long k = sc.nextInt();
long q = k, i = 0;
while(q>0)
{
q=q/10;
i++;
}
if(i<=8)
{
long r = 0;
while(k>0)
{
long d = k%10;
r=(r*10)+d;
k=k/10;
}
System.out.println("REVERSE number = "+r);
}
else
{
System.out.println("Number NOT EXIST ");
}
break;
case 2:
System.out.println("Enter a number (not more then 8 digit)");
long a = sc.nextInt();
long l = a, x = 0;
while(l>0)
{
l=l/10;
x++;
}
if(x<=8)
{
long j = a;
long t = 0;
while(j>0)
{
long d = j%10;
t=(t*10)+d;
j=j/10;
}
System.out.println("ABSOLUTE difference = "+(a-t));
}
else
{
System.out.println("Number NOT EXIST ");
}
break;
case 3:
System.out.println("Enter a number (not more then 8 digit)");
long y = sc.nextInt();
long h = y, j = 0;
while(h>0)
{
h=h/10;
j++;
}
if(j<=8)
{
long m = 9;
while(y>0)
{
long d = y%10;
y=y/10;
if(d<m)
{
m=d;
}
}
System.out.println("SMALLEST number = "+m);
}
else
{
System.out.println("Number NOT EXIST ");
}
break;
default:
System.out.println("ENVALID CHOICE");
}
}
}