Yes it's equivalent. Probably was meant 6 times with first input string, because in first example says: "Observe that the name is repeatedly displayed 5 times. (Figure-3.13 below) You will see 6 names, the first of which is input that is redisplayed."
On Feb 3, 4:32 pm, Marek Durian <[email protected]> wrote: > Hi, > > In 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.) > > 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en
