Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class loopThatSwitch
- {
- public static void main(String [] args)
- {
- for (int i = 0; i < 1; i++)
- {
- String options = JOptionPane.showInputDialog("[A] Add\n[B] Subtract\n[C] Multiply\n[exit] To exit program");
- switch(options) {
- case "exit":
- System.exit(0);
- break;
- case "A":
- String addx = JOptionPane.showInputDialog("Add");
- int add1 = Integer.parseInt(addx);
- String addy = JOptionPane.showInputDialog("Add");
- int add2 = Integer.parseInt(addy);
- int result1 = add1 + add2;
- JOptionPane.showMessageDialog(null, addx +" + " + addy + " = " + result1);
- break;
- case "B":
- String minusx = JOptionPane.showInputDialog("Subtract");
- int sub1 = Integer.parseInt(minusx);
- String minusy = JOptionPane.showInputDialog("Subtract");
- int sub2 = Integer.parseInt(minusy);
- int result2 = sub1 - sub2;
- JOptionPane.showMessageDialog(null, minusx + " - " + minusy + " = " + result2);
- break;
- case "C":
- String timesx = JOptionPane.showInputDialog("Multiply");
- int mul1 = Integer.parseInt(timesx);
- String timesy = JOptionPane.showInputDialog("Multiply");
- int mul2 = Integer.parseInt(timesy);
- int result3 = mul1 * mul2;
- JOptionPane.showMessageDialog(null, timesx + " x " + timesy + " = " + result3);
- break;
- default:
- JOptionPane.showMessageDialog(null, "Please select operations", "Error", JOptionPane.ERROR_MESSAGE);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement