-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayv.java
More file actions
97 lines (74 loc) · 1.48 KB
/
Arrayv.java
File metadata and controls
97 lines (74 loc) · 1.48 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
86
87
88
89
90
91
92
93
94
95
96
97
package coding;
import java.util.Scanner;
public class Arrayv {
public static void main(String[] args) {
// System.out.println(power(2, 10));
// Scanner sc=new Scanner(System.in);
//
// int a=sc.nextInt();
// int b=sc.nextInt();
// swap(a,b);
// System.out.println(a+" ");
}
private static int numberOfDigits(int a) {
int count = 0;
while (a != 0) {
count++;
a = a / 10;
}
return count;
}
public static boolean isArmstrong(int number) {
int temp = number;
int sum = 0;
while (temp != 0) {
int rem = temp % 10;
sum += Math.pow(rem, 3);
temp /= 10;
}
return sum == number;
}
public static void printAllArmStrongNumber(int ll, int ul) {
for (int i = ll; i < ul; i++) {
if (isArmstrong(i)) {
System.out.println(i);
}
}
}
public static int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static int lcm(int a, int b) {
return a * b / gcd(a, b);
}
public static int power(int base, int r) {
if (r != 0) {
return base * power(base, r - 1);
}
return 1;
}
public static void printAllPrimeNumber(int ll, int ul) {
for (int i = ll; i <= ul; i++) {
if(isPrimeNumber(i))
System.out.print(i+" ");
}
}
public static boolean isPrimeNumber(int number) {
boolean flag = true;
for (int i = 2; i < number / 2; i++) {
if (number % i == 0) {
flag = false;
break;
}
}
return flag;
}
public static void swap(int a, int b) {
int temp=a;
a=b;
b=temp;
}
}