-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaExpressions.java
More file actions
75 lines (71 loc) · 1.9 KB
/
LambdaExpressions.java
File metadata and controls
75 lines (71 loc) · 1.9 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
import java.util.Scanner;
public class LambdaExpressions {
static void checkEven(int a) {
if (a % 2 == 0) {
System.out.println("EVEN");
} else {
System.out.println("ODD");
}
}
static void checkPrime(int a) {
boolean key = true;
for (int i = 2; i < a; i++) {
if (a % i == 0) {
key = false;
}
}
if (key == true) {
System.out.println("PRIME");
} else {
System.out.println("COMPOSITE");
}
}
static void checkPalindrome(int a) {
int k = a;
int b, c = 0, d = 0;
while (k > 0) {
k /= 10;
d++;
}
k = a;
while (k > 0) {
d--;
b = k % 10;
c += b * Math.pow(10, d);
System.out.println(c);
k /= 10;
}
if (c == a) {
System.out.println("PALINDROME");
} else {
System.out.println("NOT PALINDROME");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k;
k = sc.nextInt();
int arr[] = new int[k];
int ar1[] = new int[k];
for (int i = 0; i < k; i++) {
arr[i] = sc.nextInt();
ar1[i] = sc.nextInt();
}
for (int i = 0; i < k; i++) {
switch (arr[i]) {
case 1:
checkEven(ar1[i]);
break;
case 2:
checkPrime(ar1[i]);
break;
case 3:
checkPalindrome(ar1[i]);
break;
default:
System.out.println("Not Enterred Correct Key");
break;
}
}
}
}