-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathematical.java
More file actions
85 lines (76 loc) · 2.01 KB
/
Copy pathMathematical.java
File metadata and controls
85 lines (76 loc) · 2.01 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.util.ArrayList;
import java.util.HashMap;
public class Mathematical {
public static void count_digits(int n) {
int count = 0;
while (n > 0) {
n /= 10;
count++;
}
System.out.println(count);
}
public static void reverse(int num) {
int reversed = 0;
while (num != 0) {
reversed = reversed * 10 + num % 10;
num /= 10;
}
System.out.println(reversed);
}
public static void gcd(int n1, int n2) {
while (n1 != 0 && n2 != 0) {
if (n1 > n2) {
n1 = n1 % n2;
} else {
n2 = n2 % n1;
}
}
int gcd = (n1 == 0) ? n2 : n1;
System.out.println(gcd);
}
public static void armstrong(int n) {
int temp = n;
int sum = 0;
int k = String.valueOf(n).length();
while (n > 0) {
sum = (int) (sum + Math.pow(n % 10, k));
n /= 10;
}
boolean ans = (sum == temp) ? true : false;
System.out.println(ans);
}
public static void printDivisors(int num) {
ArrayList<Integer> divisors = new ArrayList<>();
int temp = 1;
while (temp < Math.sqrt(num)) {
if (num % temp == 0) {
divisors.add(temp);
divisors.add(num / temp);
}
temp++;
}
System.out.println(divisors.toString());
}
public static void isPrime(int num) {
int temp = 2;
boolean ans = true;
while (temp < num) {
if (num % temp == 0) {
ans = false;
break;
}
temp++;
}
System.out.println(ans);
}
public static void main(String[] args) {
// reverse(123);
// gcd(3, 6);
// armstrong(153);
// printDivisors(6);
// count_digits(116);
// isPrime(4);
HashMap<Integer> mp = new HashMap<>();
mp.put
}
}