-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 7
More file actions
81 lines (79 loc) · 1.64 KB
/
Assignment 7
File metadata and controls
81 lines (79 loc) · 1.64 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
import java.util.*;
public class Gener {
public static void main(String[] args) {
int ch;
Scanner sc = new Scanner(System.in);
System.out.println("1.Check even or odd");
System.out.println("2.Check prime or not");
System.out.println("3.Check Whether the No. is
palindrome or not");
System.out.println("Enter your choice:");
ch = sc.nextInt();
do {
switch (ch) {
case 1
int n;
System.out.println("Enter the number you
want to check:");
n = sc.nextInt();
ArrayList<Integer> number = new ArrayList<>();
number.add(n);
System.out.println(number);
if (n % 2 == 0) {
System.out.println(number + " is an even number!");
}
else {
System.out.println(number + " is an
odd number!");
}
break;
case 2:
ArrayList<Integer> number1 = new ArrayList<>();
System.out.print("Enter the value of
n:");
n = sc.nextInt();
number1.add(n);
int count = 0;
int i;
for (i = 1; i <= n; ++i) {
if (n % i == 0) {
count++;
}
}
if (count == 2) {
System.out.println(number1 + " is
prime number!");
}
else {
System.out.println(number1 + " is not prime number!");
}
break;
case 3:
int num, r, temp;
ArrayList<Integer> number2 = new ArrayList<>();
int sum = 0;
System.out.println("Enter the number to
check Weather it is palindrome or not:");
num = sc.nextInt();
number2.add(num);
temp = num;
while (num != 0) {
r = num % 10;
sum = (sum * 10) + r;
num = num / 10;
}
if (temp == sum) {
System.out.println(number2 + " is a
palindrome number!");
}
else {
System.out.println(number2 + " is not a palindrome Number!");
}
break;
default:
break;
}
}
while(ch!=4);
}
}