-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex027.java
More file actions
64 lines (58 loc) · 1.95 KB
/
Copy pathex027.java
File metadata and controls
64 lines (58 loc) · 1.95 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package listaexercicios02;
import java.util.Scanner;
public class ex027 {
public static void somar(float a, float b) {
float resultado = a + b;
System.out.println("--- SOMAR ---");
System.out.printf("%.2f + %.2f = %.2f", a, b, resultado);;
}
public static void subtrair(float a, float b) {
float resultado = a - b;
System.out.println("--- SUBTRAIR ---");
System.out.printf("%.2f - %.2f = %.2f", a, b, resultado);
}
public static void multiplicar(float a, float b) {
float resultado = a * b;
System.out.println("--- MULTIPLICAR ---");
System.out.printf("%.2f X %.2f = %.2f", a, b, resultado);
}
public static void dividir(float a, float b) {
float resultado = a / b;
System.out.println("--- DIVIDIR ---");
System.out.printf("%.2f / %.2f = %.2f", a, b, resultado);
}
public void menu() {
Scanner input = new Scanner(System.in);
System.out.println("*--*--* CALCULADORA *--*--*");
System.out.println("[1] SOMAR");
System.out.println("[2] SUBTRAIR");
System.out.println("[3] MULTIPLICAR");
System.out.println("[4] DIVIDIR");
System.out.print("Escolha uma opção: ");
int op = input.nextInt();
System.out.print("Digite o primeiro número: ");
float a = input.nextFloat();
System.out.print("Digite o segundo número: ");
float b = input.nextFloat();
switch (op) {
case 1:
somar(a, b);
break;
case 2:
subtrair(a, b);
break;
case 3:
multiplicar(a, b);
break;
case 4:
dividir(a, b);
break;
default:
System.out.println("Opção inválida");
}
}
public static void main(String[] args) {
ex027 e1 = new ex027();
e1.menu();
}
}