Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main
- {
- public static void main(String[] args)
- {
- System.out.println("Calculator!");
- Scanner input = new Scanner(System.in);
- System.out.println("1. Add");
- System.out.println("2. Subtract");
- System.out.println("3. Multiply");
- System.out.println("4. Divide");
- int choice = input.nextInt();
- System.out.println("");
- System.out.print("Enter a number: ");
- float number1 = input.nextFloat();
- System.out.println("");
- System.out.print("Enter second number: ");
- float number2 = input.nextFloat();
- switch(choice){
- case 1:
- float addition = number1 + number2;
- System.out.printf("\nAdded!: %f", addition);
- break;
- case 2:
- float subtraction = number1 - number2;
- System.out.printf("\nSubtracted!: %f", subtraction);
- break;
- case 3:
- float multiplication = number1 * number2;
- System.out.printf("\nMultiplied!: %f", multiplication);
- break;
- case 4:
- float division = number1 / number2;
- System.out.printf("\nDivided!: %f", division);
- break;
- default:
- System.out.println("Please pick a number 1-4.");
- System.out.println("Press enter twice(?) to exit.");
- input.nextLine();
- System.exit(1);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement