-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculadora.java
30 lines (28 loc) · 994 Bytes
/
Calculadora.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
import java.util.Scanner;
/**
* Laboratório de Programação 2 - Lab 1
*
* @author Pedro Manoel
*/
public class Calculadora {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String operador = sc.nextLine();
switch (operador) {
case "+" -> System.out.format("RESULTADO: %.1f", (sc.nextFloat() + sc.nextFloat()));
case "-" -> System.out.format("RESULTADO: %.1f", (sc.nextFloat() - sc.nextFloat()));
case "*" -> System.out.format("RESULTADO: %.1f", (sc.nextFloat() * sc.nextFloat()));
case "/" -> {
float n1 = sc.nextFloat();
float n2 = sc.nextFloat();
if (n2 == 0.0) {
System.out.print("ERRO");
} else {
System.out.format("RESULTADO: %.1f", (n1 / n2));
}
}
default -> System.out.print("ENTRADA INVALIDA");
}
sc.close();
}
}