I was asked to write a program to create an \"E\" shape by using an array using
ID: 3652571 • 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
i have the original function to display this, but can't figure out how to alter this function to print the above pattern. THe original funtion is as follows:
package javaapplication1;
class JavaApplication1 {
static int array[][] = new int[7][7];
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();
}
}
}
Explanation / Answer
package javaapplication1;
public class JavaApplication1
{
public static void main(String[] args)
{
char[] array = {'E','_'};
int s =0; for(int i=0;i<7;i++) { if(i==1 || i==2|| i==4 || i==4 || i==5)
s=6;
else if(i==3)
s=3;
else
s=0;
for(int j=0;j<s;j++)
{
System.out.print(array[1]);
}
for(int j=s;j<7;j++)
{
System.out.print(array[0]);
}
System.out.println();
}
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.