|
1 | | -package sample; |
2 | | - |
3 | | -import java.util.Scanner; |
4 | | - |
5 | | -public class AmstrongNumber { |
6 | | - |
7 | | - public static void main(String[] args) { |
8 | | - |
9 | | - |
10 | | - Scanner sc1=new Scanner(System.in); |
11 | | - |
12 | | - System.out.println("Enter the From number"); |
13 | | - int userInput=sc1.nextInt(); |
14 | | - |
15 | | - //System.out.println("Enter the From number"); |
16 | | - //int userInputFrom=sc1.nextInt(); |
17 | | - |
18 | | - System.out.println("Enter the To number"); |
19 | | - int userInputTo=sc1.nextInt(); |
20 | | - |
21 | | - int userInputCopy=userInput; |
22 | | - int amstrongNumber=0; |
23 | | - |
24 | | - int remainder; |
25 | | - int quotient; |
26 | | - |
27 | | - |
28 | | - for(int i=userInputTo;i<=userInput;i++) |
29 | | - |
30 | | - { |
31 | | - while(userInput!=0) |
32 | | - { |
33 | | - remainder=userInput%10; |
34 | | - quotient=userInput/10; |
35 | | - userInput=quotient; |
36 | | - |
37 | | - amstrongNumber=amstrongNumber+(remainder*remainder*remainder); |
38 | | - } |
39 | | - |
40 | | - } |
41 | | - |
42 | | - if(amstrongNumber==userInputCopy) |
43 | | - |
44 | | - { |
45 | | - System.out.println("Amstrong"); |
46 | | - |
47 | | - } |
48 | | - else |
49 | | - { |
50 | | - System.out.println("Not Amstrong"); |
51 | | - } |
52 | | - |
53 | | - } |
54 | | - |
55 | | -} |
| 1 | +//package sample; |
| 2 | + |
| 3 | +import java.util.Scanner; |
| 4 | + |
| 5 | +public class AmstrongNumber { |
| 6 | + |
| 7 | + public static void main(String[] args) { |
| 8 | + |
| 9 | + |
| 10 | + Scanner sc1=new Scanner(System.in); |
| 11 | + |
| 12 | + System.out.println("Enter the From number"); |
| 13 | + int userInput=sc1.nextInt(); |
| 14 | + |
| 15 | + //System.out.println("Enter the From number"); |
| 16 | + //int userInputFrom=sc1.nextInt(); |
| 17 | + |
| 18 | + System.out.println("Enter the To number"); |
| 19 | + int userInputTo=sc1.nextInt(); |
| 20 | + |
| 21 | + int userInputCopy=userInput; |
| 22 | + int amstrongNumber=0; |
| 23 | + |
| 24 | + int remainder; |
| 25 | + int quotient; |
| 26 | + |
| 27 | + |
| 28 | + for(int i=userInputTo;i<=userInput;i++) |
| 29 | + |
| 30 | + { |
| 31 | + while(userInput!=0) |
| 32 | + { |
| 33 | + remainder=userInput%10; |
| 34 | + quotient=userInput/10; |
| 35 | + userInput=quotient; |
| 36 | + |
| 37 | + amstrongNumber=amstrongNumber+(remainder*remainder*remainder); |
| 38 | + } |
| 39 | + |
| 40 | + } |
| 41 | + |
| 42 | + if(amstrongNumber==userInputCopy) |
| 43 | + |
| 44 | + { |
| 45 | + System.out.println("Amstrong"); |
| 46 | + |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + System.out.println("Not Amstrong"); |
| 51 | + } |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments