This is for a friend of mine who is having trouble with Java for school.
I do know some programming, but not Java.
Scanner kbReader = new Scanner(System.in);
System.out.print("Name of item: ");
String name = kbReader.next();
System.out.println("Original price of item: $");
double price = kbReader.nextDouble();
Outputs:
Name of item: Coat
Original price of item: $
10
Why is the input for "Original price of item: $" on the next line?
I was guessing it was because I went from String to double, but can't think of a different way to do it?
If you use
System.out.println()
Java will put a newline after the output, if you use
System.out.print()
Java won't put a newline after the output.
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