I have a program that takes input from the user from the command line. Annoyingly the first time I use the scanner the inputted text goes on the next line (after the System.out.println
). However, all the other times it is on the same line as the System.out.println
.
Code:
//Create a scanner
Scanner input = new Scanner(System.in);
//Gets type
System.out.println("--Television Show or Film (t or f): ");
String type = input.nextLine();
input.close();
Output:
--Television Show or Film (t or f):
t
Desierd Output:
--Television Show or Film (t or f): t
Any help is appreciated. Also, I'm using Eclipse Console.
Use System.out.print
rather than System.out.println
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With