Sum of digits, Reverse, Palindrome & Armstrong Number Checker

Sum of digits, Reverse, Palindrome & Armstrong Number Checker:

package checker;

import java.util.Scanner;

public class Check {

public static void main(String[] args) {

int sum=0,s,temp,num,c;

System.out.println("Enter any number: ");

Scanner input=new Scanner(System.in);
num=input.nextInt();

temp=num;

System.out.println("Enter 0 for Sum of digits.");
System.out.println("Enter 1 for Reverse number.");
System.out.println("Enter 2 for Palindrome number.");
System.out.println("Enter 3 for Armstrong number.");

Scanner input0=new Scanner(System.in);
System.out.println();
c=input0.nextInt();

switch(c) {

case 0:
{
 
while(temp!=0) {
s=temp%10;
sum=sum+s;
temp=temp/10;

}
System.out.println("Sum of digits: "+sum);
break;

}

case 1:
{

while(temp!=0) {
s=temp%10;
sum=sum*10+s;
temp=temp/10;

}
System.out.println("Reverse Number: "+sum);
break;
}

case 2:
{

while(temp!=0) {
s=temp%10;
sum=sum*10+s;
temp=temp/10;

}
if(num==sum) {
System.out.println(sum+" is palindrome number.");
}
else {
System.out.println(num+" is not a palindorme number.");
}
break;
}

case 3:
{

while(temp!=0) {
s=temp%10;
sum=sum+(s*s*s);
temp=temp/10;

}
if(num==sum) {
System.out.println(num+" is a armstrong number");
}
else {
System.out.println(num+" is a not armstrong number bacause "+num+" and "+sum+" ar not equal");
}
break;

}

default :
{
System.out.println("Please Enter 0 to 3");

}


}


}

}

Comments

Popular posts from this blog

For loop C++

VALENTINE DAY PROGRAME

Charecter & space founder in c program