Scanner input = new Scanner(System.in);
System.out.println("Enter a value : ");
String s3 = input.next();
System.out.println("Enter another value: " );
String s5 = input.next();
String s = ("1= add, 2 = subtract");
int op = Integer.parseInt(s);
double result=0;
switch (op) {
case 1:
result = addValues(s3, s5);
break;
case 2:
result = subtractValues(s3, s5);
default:
System.out.println("Incorrect");
break;
}
addValues(s3, s5);
subtractValues(s3, s5);
}
private static double subtractValues(String s3, String s5)
{
double d1 = Double.parseDouble(s3);
double d2 = Double.parseDouble(s5);
double result = d1-d2;
return result;
}
private static double addValues(String s3, String s5)
{
double d1 = Double.parseDouble(s3);
double d2 = Double.parseDouble(s5);
double result = d1+d2;
return result;
}
}
I have the above code and its thorwing an exception of numberformatException. What is wrong with this code .. kindly help me out.