summaryrefslogtreecommitdiff
path: root/java/atividades/Decisao1.java
blob: 421bd081c2c868cdcfa803dd645c331059f1e295 (plain)
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.*;

class Decisao1
{
	public static void main(String args[])
	{
		int num;
		char op = 0;
		String msg = "", msgEntr = "Digite 1 p/ par/impar\nDigite 2 para positivo/negativo";

		num = Integer.parseInt(JOptionPane.showInputDialog("Digite um numero inteiro"));
		op = (JOptionPane.showInputDialog(msgEntr)).charAt(0);

		switch(op) {
			case '1':
				if (num % 2 == 0) {
					msg = msg + num + " eh par.\n";
				}
				else {
					msg = msg + num + " eh impar.\n";
				}
				break;
	
			case '2':
				if (num > 0) {
					msg = msg + num + " eh positivo.\n";
				}
				else {
					msg = msg + num + " eh negativo.\n";
				}
				break;
	
			default: JOptionPane.showMessageDialog(null, "Opcao invalida");
		}
		if (op == '1' | op == '2') {
			JOptionPane.showMessageDialog(null, msg);
		}
		System.exit(0);
	}
}