+ 1
i am getting error in java code . error is like mismatch input .
code is available on code play as knapsack code but it always show error please help
2 Antworten
+ 2
InputMismatchException in most cases occur when your code expects a certain data type to be entered but rather the user has entered something else.
Example:
As you can see below if i were to enter something like "2.47484", an InputmismatchException will be thrown.
int getNum = scanner.nextInt();
There is many ways to prevent the system from crashing. For example you can use the scanner validation methods such has hasNexInt() prior to you assigning the input value to a variable. If the expression returns true then its safe to assign the value to a variable, else print a message to the user and say whats wrong.
+ 1
thank you