Write a Java program in a class named Window that produces the following figure
ID: 664907 • Letter: W
Question
Write a Java program in a class named Window that produces the following figure as output. Use nested for loops to print the repeated parts of the figure. Once you get it to work, add one class constant to your program so that the size of the figure can be changed simply by changing that constant's value. The example output shown is at a constant size of 3, but if you change the constant, the figure should grow larger and wider proportionally.
(You must solve this problem using only ONE public static final constant, not multiple constants; and its value must be used in the way described in this problem.)
Complete program: For this problem, you are supposed to submit a complete Java program as a class with a mainmethod. (You do not need to write any import statements.)
Explanation / Answer
working java code
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
int BLOCK_SIZE;
Scanner in = new Scanner(System.in);
BLOCK_SIZE = in.nextInt();
int length = BLOCK_SIZE*4-4;
char one,two;
for(int i=0; i<=length; i++){
if(i%4!=0){one='|';two=' ';}
else{one='+';two='=';}
for(int j=0; j<=length; j++){
if(j%4==0) {
System.out.print(one);
}
else {
System.out.print(two);
}
}
System.out.println();
}
}
}
compiled on ideone
https://ideone.com/yPnmYu
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.