On 2/3/2011 8:32 AM, Marek Durian wrote:
Hi,
In Java Programming (with Passion!)
<http://www.javapassion.com/portal/java-programming-with-passion/java-programming-with-passion>,
I am doing labs from javase_control and there are two examples:
First one - the example of the while - MyFiveNamesusingwhileProject
Second one - the example of the dowhile - MyFiveNamesusingdowhileProject
The "while" example should repeated name five times as it it written,
and actually it does. (Figure-3.13: Name is repeated 5 times using
while loop)
The "do while" example should repeat name six times? It does it five
times only.
(Code-3.21: FiveNamesUsingdowhile.java 3. Build and run the program
* Right click MyFiveNamesUsingdowhileProject and select Run.
* Observe that the program prompts you to enter your name.
* Enter your name in the Input field and press Enter key. (Do not
press Close Input.)
* Observe that the name is repeatedly displayed 6 times.)
This is corrected now. Thanks for pointing this out.
-Sang Shin
In my opinion both codes do the same in this case:
First case:
int counter = 0;
while (counter < 5){
System.out.println("Repeated name W: "+ counter+" " +name);
counter++;
}
Second case:
int counter = 0;
do{
System.out.println("Repeated name: DW" +counter+" "+name);
counter++;
}while(counter < 5);
The only difference I can see is, if the condition would be changed to
"counter <0", the while cycle would not print anything, but the do
while would print one repeat name.
So my question is, if there is a mistyping in the lab material, or it
is my misunderstanding?
Thank you very much for your help.
Have a nice day:-)
Kind regards,
Marek Durian
Czech Republic
--
To post to this group, send email to
javaprogrammingwithpassion@googlegroups.com
To unsubscribe from this group, send email to
javaprogrammingwithpassion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
--
-------------------------------------------------------------------
Sang Shin, sangshinpass...@gmail.com
Founder and Chief Instructor of JavaPassion.com
http://javapassion.com/portal/instructors/sang-shin-schedule (Bio)
http://www.linkedin.com/in/javapassion (Linkedin)
Life is worth living... with Passion!
"EJB 3.0/JPA/Spring/Hibernate/Java EE 6" (Boston, March 21st-25th, 2011)
For registration, go to http://www.javapassion.com/codecamps
----------------------------------------------------------------------
--
To post to this group, send email to javaprogrammingwithpassion@googlegroups.com
To unsubscribe from this group, send email to
javaprogrammingwithpassion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en