Hi,
I'm beginner at Java. I'm confused with my simple program of using while loops
int i = 1;
while (i <= input){
System.out.prin tln("Enter description of product #" + i + " : ");
item = keyboard.nextLi ne();
System.out.prin tln("Enter price of " + item + " : ");
price = keyboard.nextDo uble();
i++;
}
I just wondering why when i run the program, the output will be:
Enter description of product #1 :
Enter price of :
3
Enter description of product #2 :
Enter price of :
2
and while i change a bit to
for (int i = 1; i <= input; i++){
System.out.prin tln("Enter description of product #" + i + " : ");
item = keyboard.nextLi ne();
}
the output will be:
Enter description of product #1 :
Enter description of product #2 :
3
really need helpp...
Many thanks.
I'm beginner at Java. I'm confused with my simple program of using while loops
int i = 1;
while (i <= input){
System.out.prin tln("Enter description of product #" + i + " : ");
item = keyboard.nextLi ne();
System.out.prin tln("Enter price of " + item + " : ");
price = keyboard.nextDo uble();
i++;
}
I just wondering why when i run the program, the output will be:
Enter description of product #1 :
Enter price of :
3
Enter description of product #2 :
Enter price of :
2
and while i change a bit to
for (int i = 1; i <= input; i++){
System.out.prin tln("Enter description of product #" + i + " : ");
item = keyboard.nextLi ne();
}
the output will be:
Enter description of product #1 :
Enter description of product #2 :
3
really need helpp...
Many thanks.
Comment