/* JAVA PROGRAM TO CHECK ARMSTRONG NUMBER
ENTERED FROM KEYBOARD */
import java.io.*;
class ArmstrongNumber{
public static void main(String[] ar)
throws IOException{
BufferedReader br= new BufferedReader(
new InputStreamReader(System.in));
System.out.print("enter the number to check armstrong number:");
int n=Integer.parseInt(br.readLine());
int a=0,k=0,temp;
temp=n;
while(n>0){
a=n%10;
n=n/10;
k=k+(a*a*a);
}
if(temp==k){
System.out.println("the number is armstrong number");
}
else{
System.out.println("the number is not armstrong number");
}
}
}
OUTPUT:
ENTERED FROM KEYBOARD */
import java.io.*;
class ArmstrongNumber{
public static void main(String[] ar)
throws IOException{
BufferedReader br= new BufferedReader(
new InputStreamReader(System.in));
System.out.print("enter the number to check armstrong number:");
int n=Integer.parseInt(br.readLine());
int a=0,k=0,temp;
temp=n;
while(n>0){
a=n%10;
n=n/10;
k=k+(a*a*a);
}
if(temp==k){
System.out.println("the number is armstrong number");
}
else{
System.out.println("the number is not armstrong number");
}
}
}
OUTPUT:
No comments:
Post a Comment