In this lab, you add nested loops to a Java program provided.
The program should print the letter E. The letter E is printed using asterisks, three across and five down. Note that this program uses System.out.print("*"); to print an asterisk without a new line.
Instructions:
Write the nested loops to control the number of rows and the number of columns that make up the letter E.
In the loop body, use a nested if statement to decide when to print an asterisk and when to print a space. The output statements have been written, but you must decide when and where to use them.
Execute the program. Observe your output.
Modify the program to change the number of rows from five to seven and the number of columns from three to five.
What does the letter E look like now?

Respuesta :

Answer:

/Create a class LetterE.

public class LetterE

{

//Define the main() function.

public static void main(String args[])

{

//Declare the variables.

final int NUM_ACROSS = 3;

final int NUM_DOWN = 5;

int row;

int column;

//Begin the for loop.

for(int k=1; k<=NUM_DOWN; k++)

{

//Begin the for loop.

for(int l=1; l<=NUM_ACROSS; l++)

{

//Check the condition.

if(k == 1 || k==5 || k == 3)

//Display the asterisk.

System.out.print("*");

// Decide when to print asterisk in column 1.

else if(l==1)

//Display the asterisk.

System.out.print("*");

//Else part of above if .

else

//Display the space.

System.out.print(" ");

}//End of for loop.

//Statement for the next line.

System.out.println();

}//End of for loop.

//End of the workdone.

System.exit(0);

}//End of the main() function.

}//End of the LetterE class.

Explanation: