2 Java Scanners | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

2 Java Scanners

So in java, you can use the scanner thing for input, but how would you do multiple inputs? I know you can do a space in the input and when getting the variable you can use .nextInt(), but I want to know if you can do it like javascript, with multiple prompts and text that explains what you can write

10th May 2021, 7:22 PM
Neurobean
Neurobean - avatar
4 Answers
+ 2
you can use same scanner object multiple times, Scanner scan = new Scanner(System.in) System.out.println("first input") String in1 = scan.nextLine() System.out.println("second input") String in2 = scan.nextLine() I hope this helps :)
10th May 2021, 7:30 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
yup, I agree with Martin Taylor 's answer, this is a limitation with Sololearn's code playground.
10th May 2021, 7:53 PM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
Oh ok Martin Taylor thx for letting me know :)
10th May 2021, 8:43 PM
Neurobean
Neurobean - avatar
0
I'll try it Apollo-Roboto but it doesn't help with the part where it explains what you input, for example in js you can do 'var b = prompt("Turtle");' and the "Turtle" would show up to guide you on what to input, or is it not possible? Edit: your idea didn't work sadly, you have to split the input into 2 lines instead of the popup coming up twice, also if you only do the 1st line the code crashes
10th May 2021, 7:33 PM
Neurobean
Neurobean - avatar