I’m new to Java and was just wondering , with the default delimiter, what will be the value of age? (Note i enter the values when prompted and then end with a ‘enter’ key)
Enter Age: 14 45 20 16 (then press enter key)
What is the value of age( 14? 16? 14452016?) and why?
Assuming you're talking about java.util.Scanner
, the default delimiter is whitespace. Therefore, if you enter "14 45 20 16" on the command line and then pressed the enter key, the nextInt
or next
call on the scanner instance would return 14. If you then call nextInt
on scanner again, you get no prompting; that would immediately return 45. Another 2 calls would return respectively 20 and 16. If you then call nextInt
a fifth time, that call would wait until you typed something.