-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPemilihanSwicth20.java
41 lines (36 loc) · 1.18 KB
/
PemilihanSwicth20.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
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
/**
* PemilihanSwicth20
*/
public class PemilihanSwicth20 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double angka1,angka2,hasil = 0;
char operator;
System.out.println("Masukkan angka 1: ");
angka1 = sc.nextDouble();
System.out.println("Masukkan angka 2: ");
angka2 = sc.nextDouble();
System.out.println("Masukkan Operator(+/-/x/:)");
operator = sc.next().charAt(0);
switch (operator) {
case '+':
hasil = angka1 + angka2;
break;
case '-':
hasil = angka2 - angka1;
break;
case 'x':
hasil = angka1*angka2;
break;
case ':':
hasil = angka2/angka1;
break;
}
if (operator=='-'||operator=='+'||operator=='*'||operator==':');
else
System.out.println("Masukkan operator yang benar dan coba ulangi kembali!");
// System.out.println(angka1+ operator +angka2+ "=" + hasil);
System.out.println(angka1+" "+operator+" "+angka2+" "+ hasil);
}
}