Review the method doStuff() . Can you successfully trace the output? Build a tab
ID: 3658993 • Letter: R
Question
Review the methoddoStuff(). Can you successfully trace the output? Build a table where you can keep track of each variable in the loop and what is created by that loop.It's fairly easy to find ourselves "running around in circles" when we design nested For loops! Sufficient care must be devoted to carefully crafting each loop to provide the desired outcome.
public static void doStuff()
{
int lines, stars;
for (lines = 0; lines < 6; lines++)
{
for(stars = 0; stars<=lines; stars++)
System.out.print('*');
System.out.println();
}
}
Explanation / Answer
Lines Stars Output Output to Console 0 0 * * 1 0 * ** 1 * 2 0 * *** 1 * 2 * 3 0 * **** 1 * 2 * 3 * 4 0 * ***** 1 * 2 * 3 * 4 * 5 0 * ****** 1 * 2 * 3 * 4 * 5 *
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.