Verifying that the value is primitive will not work. Java will not be able to compare the value with the type in this way.
One way is to use a static function Integer.parseInt(String s)to find out if the corresponding int value has been entered. Note that it throws NumberFormatException. If you can take advantage of this fact, you can get whether an integer was provided from the function.
try {
} catch (...) {
}
The second method (since you are already using a class Scanner) is to use methodsScanner hasNextInt()and nextInt()to determine:
:
if (myScanner.hasNextInt()) {
int totalAmount = myScanner.nextInt();
// do stuff here
} else {
//Int not provided
}
, , Scanner . Scanner . , (: "," "//" ..), ?
, Scanner. useDelimiter(String pattern), , . , , ( , ).
:
Scanner myScanner = ...;
String delimiter = ...;
myScanner.useDelimiter(delimiter);
API Scanner (. Scanner, ), , . , ( ).