Skip to content

Commit 85168f0

Browse files
committed
ArmstrongNumber program
1 parent 5bb9c76 commit 85168f0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Armstrong2.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Armstrong2{
2+
public static void main(String[] args){
3+
int armCounter=0;
4+
for(int j=1;j<=100000000;j++){
5+
int num = j;
6+
int temp = num;
7+
int res=0;
8+
int pc=0;
9+
while(temp>0){
10+
pc++;
11+
temp/=10;
12+
}
13+
//System.out.println("length of num = "+pc);
14+
temp=num;
15+
while(temp>0){
16+
int rem = temp%10;
17+
//System.out.println("temp : "+temp+" , rem = "+rem);
18+
int remRes = 1;
19+
if(pc>1){
20+
for(int i=0;i<pc;i++){
21+
remRes *= rem;
22+
//System.out.println("resRes : "+remRes+" , rem : "+rem);
23+
}
24+
}
25+
temp/=10;
26+
res +=remRes;
27+
}
28+
if(res==num){
29+
armCounter++;
30+
System.out.println(num+" is Armstrong number");
31+
}else{
32+
//System.out.println("Not Armstrong number");
33+
}
34+
}
35+
System.out.println("total number os armstrong number : "+armCounter);
36+
}
37+
}

0 commit comments

Comments
 (0)