forked from aromalsanthosh/Java-Lab-S3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintAmstrong.java
More file actions
35 lines (26 loc) · 763 Bytes
/
PrintAmstrong.java
File metadata and controls
35 lines (26 loc) · 763 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
//Java Program to Print Amstrong Numbers upto N
import java.util.Scanner;
class PrintAmstrong{
PrintAmstrong(int maxNumber){
System.out.println("List of the Amstrong number between 1 - " + maxNumber);
for (int num = 001; num <= maxNumber; num++){
int rem=0,org=0,result=0;
org=num;
while(org!=0)
{
rem=org%10;
result+=(rem*rem*rem);
org/=10;
}
if(num==result)
System.out.print(num+" ");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num;
System.out.println("Enter value Of N upto which Amstrong numbers are to be printed :");
num = sc.nextInt();
new PrintAmstrong(num);
}
}