-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClasseSwitch.java
More file actions
38 lines (26 loc) · 1.05 KB
/
ClasseSwitch.java
File metadata and controls
38 lines (26 loc) · 1.05 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
package pacoteSwitch;
import java.util.*;
public class ClasseSwitch {
public static void main(String[] args) {
char operacao = ' ';
Scanner entrada = new Scanner(System.in);
double n1 = 0, n2 = 0, total = 0;
System.out.print("Digite o valor do primeiro número: ");
n1 = entrada.nextDouble();
System.out.print("Digite o valor do segundo número: ");
n2 = entrada.nextDouble();
entrada.nextLine();
System.out.print("Digite a operação desejada (+,-,/,*,%): ");
operacao = entrada.nextLine().charAt(0);
switch (operacao) {
case ('+'): total = n1 + n2; break;
case ('-'): total = n1 - n2; break;
case ('/'): total = n1 / n2; break;
case ('*'): total = n1 * n2; break;
case ('%'): total = n1 % n2; break;
default: System.out.println("O caractere não é reconhecido para esta operação.");
}
if (operacao == '+' || operacao == '-' || operacao == '/' || operacao == '*' || operacao == '%')
System.out.printf("%.2f %c %.2f = %.2f", n1, operacao, n2, total);
}
}