SHARE
TWEET

Untitled

a guest Jun 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Calculations {
  4.     static void add(int a, int b) {
  5.         System.out.println(a + b);
  6.     }
  7.  
  8.     static void divide(int a, int b) {
  9.         System.out.println(a / b);
  10.     }
  11.  
  12.     static void subtract(int a, int b) {
  13.         System.out.println(a - b);
  14.     }
  15.  
  16.     static void multiply(int a, int b) {
  17.         System.out.println(a * b);
  18.     }
  19.  
  20.     public static void main(String[] args) {
  21.         Scanner scanner = new Scanner(System.in);
  22.  
  23.         String command = scanner.nextLine();
  24.         int a = Integer.parseInt(scanner.nextLine());
  25.         int b = Integer.parseInt(scanner.nextLine());
  26.  
  27.         if (command.equals("add")) {
  28.             add(a, b);
  29.         } else if (command.equals("multiply")) {
  30.             multiply(a, b);
  31.         } else if (command.equals("subtract")) {
  32.             subtract(a, b);
  33.         } else if (command.equals("divide")) {
  34.             divide(a, b);
  35.         }
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top