0
Why throw exception not add the value
5 Réponses
+ 2
Your Calculator.add() method takes 2 doubles as parameters and returns a double. An int can be passed into a method that takes a double just fine as it is implicitly converted. The problem however, is that you are using nextInt() to receive the input from the user. If the user inputs a floating point type you'll get an InputMismatchException as a double is not an int.
double res =Calculator.add(sc.nextInt(),sc.nextInt());
change this line to:
double res =Calculator.add(sc.nextDouble(),sc.nextDouble());
+ 1
Remember, Sololearn runs on a virtual machine on a server, thus you'll need the enter all the values in one input.
You split multiple inputs by pressing {ENTER}
ex:
Input:
6
7
Output:
11.00
+ 1
oh! lfound it l entered the val as6.0
8.0 so give me error
0
its adding the numbers bro
0
but not work with me only throw exception
lam enter 8
9 but only throw exception