If you try to compile the preceding code, the compiler warns you that a boolean value is required instead of an int value. What would the output be from each program if you changed the value of each program's copyFromMe string to golly gee. Explain why you think each program will have the predicted output. The modified WhileDemo displays a blank line because the first letter is a g , and thus the loop is not entered and no characters are appended to copyToMe . The modified DoWhileDemo displays golly because the first g is ignored, and the second one terminates the loop without adding the second g to the string.
Exercises Consider the following code snippet.
Explain why the output is what it is. NestedIf second string third string 3 is greater than or equal to 0, so execution progresses to the second if statement. The second if statement's test fails because 3 is not equal to 0. Thus, second string is displayed. The final println is completely outside of any if statement, so it always gets executed, and thus third string is always displayed.