import java.util.Scanner;
//To find Armstrong Number between two given number.
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
//input
int sum = 0;
System.out.println("Enter Your Number");
int n = in.nextInt();
int input = n;
while(n>0){
int lastdig = n%10; //To get the last Dig;
sum = sum + lastdig*lastdig*lastdig;
n = n/10; //removes last dig from number;
}
if(input==sum){
System.out.println("Number is Armstrong Number :" + input + " : "+ sum);
}else{
System.out.println("Number is Not Armstrong Number :" + input + " : "+ sum);
}
}
}
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