Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 *

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote