package com.tutorial4u;
import java.util.Scanner;
public class Armstrong {
public static void main(String[] args) {
int rem, sum=0,temp;
System.out.print("Enter a number to check Armstrong : ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
temp = num;
while(num!=0){
rem = num % 10;
sum = sum+rem*rem*rem;
num = num/10;
}
if(temp == sum){
System.out.println("Given number is Armstrong");
}else{
System.out.println("Given number is Armstrong");
}
}
}
Output:
Enter a number to check Armstrong : 153
Given number is Armstrong
No comments:
Post a Comment