2nd loop combined the first and second statement lines...why?

I wrote this program to calculate the price. I want to have users to enter the item name and price continuesly, then once the hit 'f', it will give them the total. I was able to enter the first item and price but then the second time around, this is what show on my screen:

Item to purchase (enter F when finished): price for this is:

It combined the first and second lines in one line. I can't figure out why.

Please help.

This is part of my code below:

for (;;)

{

String F ="F";

System.out.print("Item to purchase (enter F when finished): ");

item=sc.nextLine();

if(item.equalsIgnoreCase (F))break;

System.out.print("Price of this "+ item +" is: ");

price=sc.nextDouble();

[756 byte] By [aivon1sta] at [2007-11-27 7:54:44]
# 1
print does not output a newlin. println does.
jverda at 2007-7-12 19:36:01 > top of Java-index,Java Essentials,New To Java...
# 2

I did try that too, but it did not work.

On the first statement already used:

item=sc.nextLine();

The output is:

Item to purchase:....

price for this item:....

when I hit enter after the price, I'm expecting it to go back to:

item to purchase:...

but instead it shows:

Item to purchase: price for this item:...

Message was edited by:

aivon1st

aivon1sta at 2007-7-12 19:36:01 > top of Java-index,Java Essentials,New To Java...
# 3

Insert a sc.nextLine(); before the nextDouble.

And insert a "\n" at final of System.out.print string.

for (;;)

{

String F ="F";

System.out.print("Item to purchase (enter F when finished): \n");

item=sc.nextLine();

if(item.equalsIgnoreCase (F))break;

System.out.print("Price of this "+ item +" is:\n ");

price=sc.nextDouble();

sc.nextLine();

}

Bruno_Grassellia at 2007-7-12 19:36:01 > top of Java-index,Java Essentials,New To Java...
# 4
Thank you!..it works fine now!
aivon1sta at 2007-7-12 19:36:01 > top of Java-index,Java Essentials,New To Java...
# 5
No. Don't print \n.Instead, use println rather than print, as I stated earlier.
jverda at 2007-7-12 19:36:01 > top of Java-index,Java Essentials,New To Java...
# 6
Yes, it's better with println, like jverd wrote.
Bruno_Grassellia at 2007-7-12 19:36:01 > top of Java-index,Java Essentials,New To Java...