+ 1

Why in java program when we input variables in string datatype after int data type var we not get output??

11th Feb 2021, 7:04 AM
Anshu jha
Anshu jha - avatar
2 Respuestas
+ 3
Because the carriage return character '\n' is not discarded after the number had been read. The character '\n' abandoned in the input stream is the thing that is causing the problem.
11th Feb 2021, 7:12 AM
Ipang
0
It depends on methods you used. nextInt() method reads an int value(digits) until a non-int value encounters. then continues to read next input as required. next() method reads a word and stops after encounter a space or \n. nextLine() reads input as string type until \n encounters and input pointer goes to next line for reading next input. (But other methods stay in same line... if \n not inputted as a carriage return). hope it helps...
11th Feb 2021, 6:33 PM
Jayakrishna 🇮🇳