Advertisement
Guest User

simple calculator

a guest
Sep 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. //calculator program, will add, subtract, multiply, and maybe divide (nope i didn't make that part)
  2. import java.util.Scanner;
  3. class Main
  4. {
  5.   public static void main(String args[])
  6.   {
  7.     System.out.println("what would you like to do? \n1: add\n2: subtract\n3: multiply");
  8.     Scanner reader = new Scanner(System.in);
  9.     byte operationType = reader.nextByte();
  10.     if (operationType == 1)
  11.     {
  12.       Calculations.add();
  13.     }
  14.     else if (operationType == 2)
  15.     {
  16.       Calculations.subtract();
  17.     }
  18.     else if (operationType == 3)
  19.     {
  20.       Calculations.multiply();
  21.     }
  22.   }
  23. }
  24.  
  25. class Calculations
  26. {
  27.   static void add()
  28.   {
  29.     Scanner reader2 = new Scanner(System.in);
  30.     int x = reader2.nextInt();
  31.     int y = reader2.nextInt();
  32.     int answer = x + y;
  33.     System.out.println(x
  34.                          + " + "
  35.                          + y
  36.                          + " = "
  37.                          + answer);
  38.   }
  39.   static void subtract()
  40.   {
  41.     Scanner reader2 = new Scanner(System.in);
  42.     int x = reader2.nextInt();
  43.     int y = reader2.nextInt();
  44.     int answer = x - y;
  45.     System.out.println(x
  46.                       + " - "
  47.                       + y
  48.                       + " = "
  49.                       + answer);
  50.   }
  51.   static void multiply()
  52.   {
  53.     Scanner reader2 = new Scanner(System.in);
  54.     int x = reader2.nextInt();
  55.     int y = reader2.nextInt();
  56.     int answer = x * y;
  57.     System.out.println(x
  58.                       + " * "
  59.                       + y
  60.                       + " = "
  61.                       + answer);
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement