// LetterE.java - This program prints the letter E with 3 asterisks // across an
ID: 3815062 • Letter: #
Question
// LetterE.java - This program prints the letter E with 3 asterisks
// across and 5 asterisks down.
// Input: None.
// Output: Prints the letter E.
public class LetterE
{
public static void main(String args[])
{
final int NUM_ACROSS = 3; // Number of asterisks to print across.
final int NUM_DOWN = 5; // Number of asterisks to print down.
int row; // Loop control for row number.
int column; // Loop control for column number.
// This is the work done in the detailLoop() method
// Write a loop to control the number of rows.
// Write a loop to control the number of columns
// Decide when to print an asterisk in every column.
System.out.print("*");
// Decide when to print asterisk in column 1.
System.out.print("*");
// Decide when to print a space instead of an asterisk.
System.out.print(" ");
// Figure out where to place this statement that prints a newline.
System.out.println();
// This is the work done in the endOfJob() method
System.exit(0);
} // End of main() method.
} // End of LetterE class.
Nesting Loops In this lab, you add nested loops to a Java program provided with the data files for this book. The program should print the letter E, as shown in Figure 5-2. The letter E is printed using asterisks, three across and five down. Note that this program uses System. Outprint to print an asterisk without a new line. Developer Command Prompt f... Java java LetterE C: Java Figure 5.2 Letter E printed by ava program 1. Open the source code file named LetterEjava using Notepad or the text editor of your choice. 2. Write the nested loops to control the number of rows and the number of columns that make up the letter E. 3. 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. 4. Save this source code file in a directory of your choice, and then make that directory your working directory. 5. Compile the source code file, LetterEjava. 6. Execute the program. Your letter Eshould look like the letter Ein Figure 5-2. 7. 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 Elook like now?Explanation / Answer
HI, Please find my implementation.
//LetterE.java - This program prints the letter E with 3 asterisks
//across and 5 asterisks down.
//Input: None.
//Output: Prints the letter E.
public class LetterE
{
public static void main(String args[])
{
final int NUM_ACROSS = 3; // Number of asterisks to print across.
final int NUM_DOWN = 5; // Number of asterisks to print down.
int row; // Loop control for row number.
int column; // Loop control for column number.
// This is the work done in the detailLoop() method
// Write a loop to control the number of rows.
for(int i=1; i<=NUM_DOWN; i++){
// Write a loop to control the number of columns
for(int j=1; j<=NUM_ACROSS; j++){
// Decide when to print an asterisk in every column.
if(i == 1 || i==5 || i == 3)
System.out.print("*");
// Decide when to print asterisk in column 1.
else if(j==1)
System.out.print("*");
// Decide when to print a space instead of an asterisk.
else
System.out.print(" ");
// Figure out where to place this statement that prints a newline.
}
System.out.println();
}
// This is the work done in the endOfJob() method
System.exit(0);
} // End of main() method.
} // End of LetterE class.
/*
Sample run:
***
*
***
*
***
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.