import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Your Number : ");
int n = in.nextInt();
System.out.println("Your number is : " + ArmStrong(n));
}
static boolean ArmStrong(int n){
int sum = 0;
int num = n;
while(n>0){
int lastdig = n%10;
sum = sum+lastdig*lastdig*lastdig;
n=n/10;
}
if(sum==num){
return true;
}
else{
return false;
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter