import java.io.*; class calculatorEx { public calculatorEx() { System.out.println("constructor invoked"); } public void calc() { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int a, b,c, d,ch; try { System.out.println("Enter the value of a"); a = Integer.parseInt(br.readLine()); System.out.println("Enter the value of b"); b = Integer.parseInt(br.readLine()); System.out.println("Enter the value of c "); c = Integer.parseInt(br.readLine()); System.out.println("\n-----Main Menu-----\n"); System.out.println("1.Addition"); System.out.println("2.Multiplication"); System.out.println("3. Subtraction"); System.out.println("4. Average"); System.out.println("------------------------------------------------------------------------"); System.out.println("\nEnter the function which u want to perform\n"); ch = Integer.parseInt(br.readLine()); switch(ch) { case '1': d = a + b + c; System.out.println("The result is " + d); break; case '2' : d = a * b * c; System.out.println("The result is " + d); break; case '3' : d = a - b - c; System.out.println(" The result is" + d); break; case '4': d = a + b + c/2; System.out.println("The result is " + d); break; default: System.out.println(" Oops! wrong choice"); break; } } catch(IOException ca) { System.out.println("Exception caught" + ca); } } public static void main(String ar[]) { calculatorEx calc1 = new calculatorEx(); calc1.calc(); } }
switch(ch) { case 1: d = a + b + c; System.out.println("The result is " + d); break; case 2: d = a * b * c; System.out.println("The result is " + d); break; case 3: d = a - b - c; System.out.println(" The result is" + d); break; case 4: d = a + b + c/2; System.out.println("The result is " + d); break; default: System.out.println(" Oops! wrong choice"); break; } }
case '1':
case 1:
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)