Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Main
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         System.out.println("Calculator!");
  8.         Scanner input = new Scanner(System.in);
  9.         System.out.println("1. Add");
  10.         System.out.println("2. Subtract");
  11.         System.out.println("3. Multiply");
  12.         System.out.println("4. Divide");
  13.         int choice = input.nextInt();
  14.         System.out.println("");
  15.         System.out.print("Enter a number: ");
  16.         float number1 = input.nextFloat();
  17.         System.out.println("");
  18.         System.out.print("Enter second number: ");
  19.         float number2 = input.nextFloat();
  20.         switch(choice){
  21.             case 1:
  22.                 float addition = number1 + number2;
  23.                 System.out.printf("\nAdded!: %f", addition);
  24.                 break;
  25.             case 2:
  26.                 float subtraction = number1 - number2;
  27.                 System.out.printf("\nSubtracted!: %f", subtraction);
  28.                 break;
  29.             case 3:
  30.                 float multiplication = number1 * number2;
  31.                 System.out.printf("\nMultiplied!: %f", multiplication);
  32.                 break;
  33.             case 4:
  34.                 float division = number1 / number2;
  35.                 System.out.printf("\nDivided!: %f", division);
  36.                 break;
  37.             default:
  38.                 System.out.println("Please pick a number 1-4.");
  39.                 System.out.println("Press enter twice(?) to exit.");
  40.                 input.nextLine();
  41.                 System.exit(1);
  42.                 break;
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement