-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitchCase.java
More file actions
40 lines (36 loc) · 1.32 KB
/
Copy pathSwitchCase.java
File metadata and controls
40 lines (36 loc) · 1.32 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
import javax.swing.*;
public class SwitchCase {
public static void main(String enter[]){
int num;
char op = 0;
String msg = "", msgEnt = "Enter the number 1 for Odd / Even\n Enter the number 2 for positive / negative.";
num = Integer.parseInt(JOptionPane.showInputDialog("Enter a integer number"));
op = (JOptionPane.showInputDialog(msgEnt)).charAt(0);
switch(op){
case '1': {
if(num % 2 == 0){
msg = msg + num + " is Even.\n";
JOptionPane.showMessageDialog(null, msg);
}
else {
msg = msg + num + " is Odd.\n";
JOptionPane.showMessageDialog(null, msg);
}
break;
}
case '2': {
if(num > 0){
msg = msg + num + " is positive.\n";
JOptionPane.showMessageDialog(null, msg);
}
else {
msg = msg + num + " is negative.\n";
JOptionPane.showMessageDialog(null, msg);
}
break;
}
default: JOptionPane.showMessageDialog(null, "Invalid option, uncatched operation");
}
System.exit(0);
}
}