File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ "Check Armstrong"
3+ Write a Program to determine if the given number is Armstrong number or not. Print true if number is armstrong, otherwise print false.
4+ An Armstrong number is a number (with digits n) such that the sum of its digits raised to nth power is equal to the number itself.
5+ For example,
6+ 371, as 3^3 + 7^3 + 1^3 = 371
7+ 1634, as 1^4 + 6^4 + 3^4 + 4^4 = 1634
8+ Input Format :
9+ Integer n
10+ Output Format :
11+ true or false
12+ Sample Input 1 :
13+ 1
14+ Sample Output 1 :
15+ true
16+ Sample Input 2 :
17+ 103
18+ Sample Output 2 :
19+ false
20+ */
21+
22+ import java.util.Scanner;
23+ import java.lang.Math;
24+ public class Main {
25+ public static void main(String[] args)
26+ {
27+ Scanner sc=new Scanner(System.in);
28+ int n=sc.nextInt();
29+ int k=n;
30+ int temp=0;
31+ int modulus=0;
32+ int store=n;
33+ int count =0;
34+ double power=0;
35+ for(int c=store;c>=1;c--)
36+ {
37+ modulus=store%10;
38+ store=store/10;
39+ if(modulus >0)
40+ {
41+ count++;
42+ }
43+ }
44+ for(int i=n;i>=1;i--)
45+ {
46+ temp=n%10;
47+ if(temp>=0)
48+ {
49+ power= (double)(power+Math.pow(temp,count));
50+ }
51+ n=n/10;
52+ temp=0;
53+ }
54+ if(power==k)
55+ {
56+ System.out.print(true);
57+ }
58+ else
59+ {
60+ System.out.print(false);
61+ }
62+ sc.close();
63+ }
64+ }
You can’t perform that action at this time.
0 commit comments