- Since 153 = 1*1*1 + 5*5*5 + 3*3*3. So 153 is an Armstrong number
- Since 12 is not equal to 1*1*1+2*2*2. So 12 is not an Armstrong number
//Here start Example for armstronNumber have or not
// Using by Scanner
import java.util.Scanner;
public class ArmstrongNumber { public static void main(String args[]) { int n, nu, num=0, rem; Scanner scan = new Scanner(System.in); System.out.print("Enter any Positive Number : "); n = scan.nextInt(); nu = n; while(nu != 0) { rem = nu%10; num = num + rem*rem*rem; nu = nu/10; } if(num == n) { System.out.print("Armstrong Number"); } else { System.out.print("Not an Armstrong Number"); } } }
0 comments:
Post a Comment