sir !
I have written the code in java for calculator using switch-case statement .
but i select any case it shows message "Oops! wrong choice" that i have wrote in default statement.
here's the program:
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();
}
}