import java.io.*;
public class Calculator{
public static void main(String[] args){
BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in));
int x=1, y=1;
String Str_1,Str_2;
System.out.println("Enter an Equation: ");
try
{
Str_1=dataIn.readLine();
System.out.print("Enter another Equation: ");
Str_2=dataIn.readLine();
x=Integer.parseInt(Str_1);
y=Integer.parseInt(Str_2);
x = x+y;
x = x-y;
x = x*y;
x = x/y;
}
catch(ArithmeticException e)
{
System.out.println("Divide by zero ERROR.");
}
catch(NumberFormatException e)
{
System.out.println("Invalid number entered.");
}
catch(Exception e)
{
System.out.println("Invalid number entered.");
}
finally
{
int add=x+y;
int minus=x-y;
int multiply=x*y;
int divide=x/y;
switch (x)
{
case'+':
System.out.println("The answer is: "+add);
break;
case'-':
System.out.println("The answer is: "+minus);
break;
case'*':
System.out.println("The answer is: "+multiply);
break;
case'/':
System.out.println("The answer is: "+divide);
break;
}
}
}
}
when i enter an equation it doesn't give me answers... i need to know what's the problem and how it will work. thanks.