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

I was asked to write a program to create an \"E\" shape by using an array using

ID: 3652551 • Letter: I

Question

I was asked to write a program to create an "E" shape by using an array using java. The final result should be as follows:

EEEEEEE
E
E
EEEE
E
E
EEEEEEE

The code I have thus far is as follows:



package javaapplication1;

class JavaApplication1 {

static int array[][] = new int[7][7];
static int i, j;

public static void main(String[] args) {

for (i = 0; i < 4; i++) {
array[i][6] = 1;
array[i][0] = 1;
}
array[1][3] = 1;
array[2][3] = 1;

for (i = 0; i < 7; i++) {
array[0][i] = 1;
}

for (i = 6; i >= 0; i--) {
for (j = 6; j >= 0; j--) {
if (array[j][i] != 0) {
System.out.print("E");
}
}
}
for (i = 6; i >= 0; i--) {
for (j = 6; j >= 0; j--) {
if (array[i][j] != 0) {
System.out.print("E");
}
}
}
System.out.println("");
/*
* System.out.print(" Normal 90 degrees 180 degrees ");
* System.out.printf("
*
* private static double normal() {
*
* int[] [] x = {{7, 7, 7, 7, 7, 7, 7}. {7}, {7}, {7, 7, 7, 7}, {7},
* {7}, {7, 7, 7, 7, 7, 7, 7}};
*
*
*/
}
}

This code is also expected to show the same "E" shape rotated 90 and 180 degrees, but primarily
I simply cannot find the logic in what I'm doing wrong to create the original shape...When I run this program, it simply gives me a single line of "Es" Can I get a working program to understand the logic?

Explanation / Answer

Please rate...

Program Pattern2.java

=======================================================

class Pattern2
{
    public static void main(String args[])
    {
        char ar[]={'E','E','E','E','E','E','E'};
        int i,j,s=0;
        for(i=0;i<ar.length;i++)
        {
            if(i==1||i==2||i==4||i==5)s=1;
            else if(i==3)s=4;
            else s=7;
            for(j=0;j<s;j++)
            {
                System.out.print(ar[i]);
            }
            System.out.println();
        }
    }
}

====================================================

Sample output:

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