+ 5
How to like make multiple scanners at once in java
I made this code import java.util.Scanner; public class Program { public static void main (String[] args) { Scanner firstname = new Scanner(System.in); Scanner lastname = new Scanner(System.in); Scanner age = new Scanner(System.in); System.out.println("My name is " + firstname.nextLine() + " " + lastname.nextLine() + " " + "and I am " + age.nextInt() + " years old." ); } } but it doesn't work... help me
5 Respuestas
+ 7
you no need to have one Scanner object for every input, you can use just one for all inputs, just read input first and you can put that inputs in some variables and then printing it...
+ 5
You don't need multiple scanners, like so:
https://code.sololearn.com/cQ4A2oJ7PdiN/?ref=app
+ 4
your code is correct as I try but make sure you enter correct inputs.
+ 1
See some further info here. Scanner isn't really the thing taking data in, but what is allowing you to use the data taken in
https://www.sololearn.com/Discuss/1032676/?ref=app
+ 1
Thank you guys so much... it was very helpful