/* Illustrates if-else-if decision making * Suggested exercises: * - Use one print for the result after the if's * - Replace the if's with a switch (use op.charAt(0)) * - Check for division by 0 * - Validate if the input is numeric (use Type.java) */ import java.util.Scanner; class Calculator { public static void main (String[] args) { double a, b, result=0; String op; Scanner scan = new Scanner(System.in); System.out.print("Enter a two argument arithmetic expression: "); a = scan.nextDouble(); op = scan.next(); b = scan.nextDouble(); if (op.equals("+")) System.out.println(a+op+b+" = "+(a+b)); else if (op.equals("-")) System.out.println(a+op+b+" = "+(a-b)); else if (op.equals("*")) System.out.println(a+op+b+" = "+(a*b)); else if (op.equals("/")) System.out.println(a+op+b+" = "+(a/b)); else System.out.println("Invalid operation: "+op); } }