-
Notifications
You must be signed in to change notification settings - Fork 2
/
12.2 Multiple Operation.java
89 lines (68 loc) · 2.51 KB
/
12.2 Multiple Operation.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Sajal and Ruhi are playing a game. Sajal is going to tell one number and one operation (Even, Odd, Prime and Factorial), Ruhi have to apply the operation and tell the output.
Input Format
Two space seperated numbers, first number on which need to apply operation and second number will be 1 for checking the number is even or not, 2 for checking number is odd or not, 3 for checking number is prime or not and 4 for calculating factorial of number.
Constraints
First number will be positive integer value. Second number can be in range of 1 to 4.
Output Format
Yes / No for first three operations and an integer value if operation four is performed.
Sample Input 0
5 1
Sample Output 0
No
Sample Input 1
5 4
Sample Output 1
120
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
//take input .pkp
int operand = sc.nextInt();
int operation = sc.nextInt();
//addtional variable used for operation no. 3 & 4;
boolean check = true;
int result = 1;
switch(operation)
{
case 1:// CHECK FOR EVEN.PKP
if(operand%2==0)
System.out.print("Yes");
else
System.out.print("No");
break;
case 2:// CHECK FOR ODD.PKP
if(operand%2!=0)
System.out.print("Yes");
else
System.out.print("No");
break;
case 3: // CHECK FOR PRIME
if(operand==1)
System.out.print("Yes");
else
for(int i=2;i*i<operand;i++)
{
if(operand%i==0)
{
System.out.print("No");
check = false;
break;
}
}
if(check==true)
System.out.print("Yes");
break;
case 4://FIND FACTORIAL
for(int i=1;i<=operand;i++)
{
result *= i;
}
System.out.print(result);
}
}
}