Write a Java program to check whether the number is a trunk number or not? Java Code\Program for finding Trunk Number - vishmy1.bllogspot.com
What is a Trunk Number?
A Trunk Number is a number whose reverse is larger than itself.
Example:- 155 reverse 551 is a Trunk Number.
Q- Write a Java program to check whether the number is a trunk number or not?
Ans - Java program to check whether the number is a trunk number or not.
import java.util.*;
class Trunk_Number
{
public static void main()
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a Number to check the number is trunk or not");
int n=scan.nextInt();
int m = n,r, p=0;
while(n>0)
{
r=n%10;
p=p*10+r;
n=n/10;
}
if(p>n)
{
System.out.println("This is a Trunk Number");
}
else
{
System.out.println("This is not a Trumk Nummber");
}
}
}
0 Comments