Multiple inputs in a single line | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Multiple inputs in a single line

How to take multiple inputs in a single line in java?

1st Apr 2020, 10:48 AM
Arnab Sarkar
Arnab Sarkar - avatar
2 Answers
+ 1
If you use nextLine(), it reads entire line as one input. Remaing methods stop reading when a space encounters... So you can input by multiple inputs by space separating by those remaining methods... Ex: next() method for single input strings..
1st Apr 2020, 11:19 AM
Jayakrishna 🇮🇳
+ 2
enter data separated by space (default) and read it as usual Scanner in = new Scanner(System.in); // enter as one line: ab cd ef System.out.println(in.next() ); System.out.println(in.next() ); System.out.println(in.next() );
1st Apr 2020, 2:45 PM
zemiak