Skip to content

Commit e8196c0

Browse files
authored
Merge pull request #118 from AjiAshwathram/AjiAshwathram-patch-1
Adding new file
2 parents c8a368d + 7b5afcd commit e8196c0

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

Armstrong.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import java.util.Scanner;
2+
import java.lang.Math;
3+
public class Armstrong
4+
{
5+
static boolean isArmstrong(int n)
6+
{
7+
int temp, digits=0, last=0, sum=0;
8+
temp=n;
9+
10+
while(temp>0)
11+
{
12+
temp = temp/10;
13+
digits++;
14+
}
15+
16+
temp = n;
17+
18+
while(temp>0)
19+
{
20+
last = temp % 10;
21+
sum += (Math.pow(last, digits));
22+
temp = temp/10;
23+
}
24+
25+
if(n==sum)
26+
27+
return true;
28+
29+
else return false;
30+
}
31+
32+
public static void main(String args[])
33+
{
34+
int num;
35+
Scanner sc= new Scanner(System.in);
36+
System.out.print("Enter the max: ");
37+
38+
num=sc.nextInt();
39+
System.out.println("Armstrong Number up to "+ num + " are: ");
40+
sc.close();
41+
42+
for(int i=0; i<=num; i++)
43+
if(isArmstrong(i))
44+
System.out.print(i+ ", ");
45+
}
46+
}

0 commit comments

Comments
 (0)