└── java5.txt /java5.txt: -------------------------------------------------------------------------------- 1 | package Programs; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ArmstrongNumber { 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | 11 | System.out.println("Enter the Number to check Armstrong Numbers : "); 12 | 13 | int n1=sc.nextInt(); 14 | 15 | boolean armstrong=isArmstrong(n1); 16 | 17 | if(armstrong) 18 | { 19 | System.out.println("Armstrong"); 20 | } 21 | else 22 | { 23 | System.out.println("not armstrong"); 24 | } 25 | 26 | System.out.println("enter the 2 numbers to check the range for "); 27 | 28 | int num1=sc.nextInt(); 29 | int num2=sc.nextInt(); 30 | 31 | IsRangeArmstrong(num1,num2); 32 | 33 | } 34 | 35 | protected static boolean isArmstrong(int n) 36 | { 37 | int c=0; 38 | 39 | int temp = n; 40 | int temp1=n; 41 | 42 | int sum=0; 43 | 44 | while(n>0) 45 | { 46 | c++; 47 | 48 | n=n/10; 49 | } 50 | 51 | while(temp>0) 52 | { 53 | int rem=temp%10; 54 | 55 | sum=sum+(int)(Math.pow(rem,c)); 56 | 57 | temp=temp/10; 58 | 59 | } 60 | 61 | if(temp1==sum) 62 | { 63 | return true; 64 | } 65 | return false; 66 | } 67 | 68 | 69 | private static void IsRangeArmstrong(int n1,int n2) 70 | { 71 | int count=0; 72 | for(int i=n1;i<=n2;i++) 73 | { 74 | if(isArmstrong(i)) 75 | { 76 | count++; 77 | System.out.println(i); 78 | } 79 | } 80 | 81 | System.out.println("The Number Count is: " + count); 82 | } 83 | 84 | 85 | 86 | } 87 | --------------------------------------------------------------------------------