Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //calculator program, will add, subtract, multiply, and maybe divide (nope i didn't make that part)
- import java.util.Scanner;
- class Main
- {
- public static void main(String args[])
- {
- System.out.println("what would you like to do? \n1: add\n2: subtract\n3: multiply");
- Scanner reader = new Scanner(System.in);
- byte operationType = reader.nextByte();
- if (operationType == 1)
- {
- Calculations.add();
- }
- else if (operationType == 2)
- {
- Calculations.subtract();
- }
- else if (operationType == 3)
- {
- Calculations.multiply();
- }
- }
- }
- class Calculations
- {
- static void add()
- {
- Scanner reader2 = new Scanner(System.in);
- int x = reader2.nextInt();
- int y = reader2.nextInt();
- int answer = x + y;
- System.out.println(x
- + " + "
- + y
- + " = "
- + answer);
- }
- static void subtract()
- {
- Scanner reader2 = new Scanner(System.in);
- int x = reader2.nextInt();
- int y = reader2.nextInt();
- int answer = x - y;
- System.out.println(x
- + " - "
- + y
- + " = "
- + answer);
- }
- static void multiply()
- {
- Scanner reader2 = new Scanner(System.in);
- int x = reader2.nextInt();
- int y = reader2.nextInt();
- int answer = x * y;
- System.out.println(x
- + " * "
- + y
- + " = "
- + answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement