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

Java- Fill in the blanks Print numbers 0, 1, 2, ..., userNum as shown, with each

ID: 3592228 • Letter: J

Question

Java- Fill in the blanks

Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints:

--------------------------------------------

public class NestedLoop {
public static void main (String [] args) {
int userNum = 0;
int i = 0;
int j = 0;

/* Your solution goes here */

return;
}
}

----------------------------------------------------

Given numRows and numCols, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numCols = 3 prints:

-----------------------------------------------------------

public class NestedLoops {
public static void main (String [] args) {
int numRows = 2;
int numCols = 3;

// Note: You'll need to declare more variables

/* Your solution goes here */

System.out.println("");

return;
}
}

Explanation / Answer

1.

public class NestedLoop {

public static void main (String [] args) {

int userNum = 0;

int i = 0;

int j = 0;

/* Your solution goes here */

for(;i<4;i++)

{

for(j=0;j<i;j++)

{

System.out.print(" ");

}

System.out.print(userNum++ + " ");

}

return;

}

}

2.

public class NestedLoops {

public static void main (String [] args) {

int numRows = 2;

int numCols = 3;

// Note: You'll need to declare more variables

/* Your solution goes here */

int a=1;

char b;

for(int i=1; i<=numRows; i++)

{

b = 'A';

for(int j=1; j<=numCols; j++)

{

System.out.println(i + "" + b);

b += 1;

}

a++;

}

System.out.println("");

return;

}

}

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