-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAmstrongNumber.java
More file actions
55 lines (35 loc) · 869 Bytes
/
AmstrongNumber.java
File metadata and controls
55 lines (35 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package sample;
import java.util.Scanner;
public class AmstrongNumber {
public static void main(String[] args) {
Scanner sc1=new Scanner(System.in);
System.out.println("Enter the From number");
int userInput=sc1.nextInt();
//System.out.println("Enter the From number");
//int userInputFrom=sc1.nextInt();
System.out.println("Enter the To number");
int userInputTo=sc1.nextInt();
int userInputCopy=userInput;
int amstrongNumber=0;
int remainder;
int quotient;
for(int i=userInputTo;i<=userInput;i++)
{
while(userInput!=0)
{
remainder=userInput%10;
quotient=userInput/10;
userInput=quotient;
amstrongNumber=amstrongNumber+(remainder*remainder*remainder);
}
}
if(amstrongNumber==userInputCopy)
{
System.out.println("Amstrong");
}
else
{
System.out.println("Not Amstrong");
}
}
}