-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharmstrong.java
68 lines (56 loc) · 1.6 KB
/
armstrong.java
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
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.Scanner;
public class armstrong {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Sayı Giriniz :");
int number = input.nextInt();
int basNumber = 0;
int tempNumber = number;
int basValue;
int result = 0;
int basPow;
while (tempNumber != 0) {
tempNumber /= 10;
basNumber++;
}
tempNumber = number;
while (tempNumber != 0) {
basValue = tempNumber % 10;
// 1*1*1*1 = 1^4
basPow = 1;
for (int i = 1; i <= basNumber; i++) {
basPow *= basValue;
}
result += basPow;
tempNumber /= 10;
}
if (result == number) {
System.out.println(number + " sayısı bir Armstrong sayıdır.");
} else {
System.out.println(number + " sayısı bir Armstrong sayısı değildir.");
}
/*
int a = 2451, basamakSayisi = 0, numberCounter = 0;
// Basamak Sayısı Bulma İşlemi
// 2451 / 10 = 245
// 245 / 10 = 24
// 24 / 10 = 2
// 2 / 10 = 0
// 0 / 10 = 0
while (a != 0) {
a /= 10;
numberCounter++;
}
// Bir sayının son basamağını bulma
// 2451 % 10 = 1
int b = 2451;
int c = b % 10;
int sub = 2, sup = 3;
int result = 1;
for (int i = 1; i <= sup; i++ ){
result *= sub;
}
System.out.println(result);
*/
}
}