Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package learning;
- import javax.swing.JOptionPane;
- public class Learning
- {
- public static void main(String[]args)
- {
- float angka1 = 0;
- float angka2 = 0;
- float hasil = 0;
- String angkaSatu = JOptionPane.showInputDialog("Masukkan angka pertama");
- angka1 = Float.parseFloat(angkaSatu);
- String angkaDua = JOptionPane.showInputDialog("Masukkan angka kedua");
- angka2 = Float.parseFloat(angkaDua);
- String pilihan = JOptionPane.showInputDialog("Masukkan operator (+, -, /, *)");
- switch(pilihan)
- {
- case "+":
- {
- hasil = angka1 + angka2;
- break;
- }
- case "-":
- {
- hasil = angka1 - angka2;
- }
- case "/":
- {
- hasil = angka1 / angka2;
- break;
- }
- case "*":
- {
- hasil = angka1 * angka2;
- break;
- }
- }
- String hasilOperasi = String.valueOf(hasil);
- JOptionPane.showMessageDialog(null, "Hasil " + hasilOperasi);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement