Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class counter
- {
- public static void main(String [] args)
- {
- int counter = 1;
- do
- {
- String options = JOptionPane.showInputDialog("[A] Add\n[B] Subtract\n[C] Multiply\n[D] Divide\n[E] Maximum\n[F] Minimum\n[G] Square root\n[exit] To exit");
- if(options.isEmpty())
- {
- JOptionPane.showMessageDialog(null, "Nothing selected");
- }
- if (options.equalsIgnoreCase("a"))
- {
- String addX = JOptionPane.showInputDialog("Enter first number to add");
- String addY = JOptionPane.showInputDialog("Enter second number to add");
- int addA = Integer.parseInt(addX);
- int addB = Integer.parseInt(addY);
- int result = addA + addB;
- JOptionPane.showMessageDialog(null, result);
- }
- else if (options.equalsIgnoreCase("b"))
- {
- String subX = JOptionPane.showInputDialog("Enter first number to subtract");
- String subY = JOptionPane.showInputDialog("Enter second number to subtract");
- int subA = Integer.parseInt(subX);
- int subB = Integer.parseInt(subY);
- int result = subA - subB;
- JOptionPane.showMessageDialog(null, result);
- }
- else if(options.equalsIgnoreCase("c"))
- {
- String mulX = JOptionPane.showInputDialog("Enter first number to multiply");
- String mulY = JOptionPane.showInputDialog("Enter second number to multiply");
- int mulA = Integer.parseInt(mulX);
- int mulB = Integer.parseInt(mulY);
- int result = mulA * mulB;
- JOptionPane.showMessageDialog(null, result);
- }
- else if (options.equalsIgnoreCase("Exit"))
- {
- int result = JOptionPane.showConfirmDialog(null, "Do you want to exit the program?", "Exit", JOptionPane.YES_NO_OPTION);
- if (result == JOptionPane.YES_OPTION)
- {
- System.exit(0);
- }
- }
- else if (options.equalsIgnoreCase("D"))
- {
- String divX = JOptionPane.showInputDialog("Enter number to divide");
- String divY = JOptionPane.showInputDialog("Enter number to divide first number");
- int divA = Integer.parseInt(divX);
- int divB = Integer.parseInt(divY);
- int result = (divA / divB);
- JOptionPane.showMessageDialog(null, result);
- }
- else if (options.equalsIgnoreCase("E"))
- {
- String maxX = JOptionPane.showInputDialog("Enter number");
- String maxY = JOptionPane.showInputDialog("Enter another number");
- int maxA = Integer.parseInt(maxX);
- int maxB = Integer.parseInt(maxY);
- int result = Math.max(maxA, maxB);
- JOptionPane.showMessageDialog(null, result);
- }
- else if (options.equalsIgnoreCase("F"))
- {
- String minX = JOptionPane.showInputDialog("Enter number");
- String minY = JOptionPane.showInputDialog("Enter another number");
- int minA = Integer.parseInt(minX);
- int minB = Integer.parseInt(minY);
- int result = Math.min(minA, minB);
- JOptionPane.showMessageDialog(null, result);
- }
- else if(options.equalsIgnoreCase("G"))
- {
- String sqrtX = JOptionPane.showInputDialog("Enter number to get square root");
- double sqrtA = Double.parseDouble(sqrtX);
- int result = (int)Math.sqrt(sqrtA);
- JOptionPane.showMessageDialog(null, result);
- }
- }while (counter <= 10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement