Question 2 – 2-D character arrays, switch and nested loops Welcome to the Decora
ID: 3733387 • Letter: Q
Question
Question 2 – 2-D character arrays, switch and nested loops
Welcome to the Decorated Square Drawing Program!I What type of square would you like? 1 Full square 2 - Hollow square 3AnX 4- Horizontal Bars 5 - Vertical Bars 6 Diagonal Bars 7 Integer Filled Square 8 Checkered (must be a multiple of 4) 9 - Quit Enter your choice (1 to 9): Sorry! That is an illegal choice Enter your choice (1 to 9): How many rows and columns (min 4 & max 20)? which character do you want to fill your square with?e Here is your pattern What type of square would you like? 1 - Full square 2 - Hollow square 3- An X 4- Horizontal Bars 5 - Vertical Bars 6 Diagonal Bars 7 Integer Filled Square 8 Checkered (must be a multiple of 4) 9 - Quit Enter your choice (1 to 9): 2 How many rows and columns (min 4 & max 20)? Which character do you want for the border?Explanation / Answer
public static void main(String[] args)
{
int ch, Length, x;
char c;
System.out.println("Menu: 1. Full square
2.Hollow square
3. An X
4. Horizontal bars
5. Vertical bars
6. Diagnol bars
7. Integer filled numbers
8. Checkered (must multiplied by 4)
9. Quit Enter your choice:");
ch=s.nextInt();
System.out.println("Enter size of square");
Length=s.nextInt();
switch (ch)
{
case 1: System.out.println("Enter filled character");
c=s.nextChar();
square(Length, c);
break;
case 2: System.out.println("Enter filled character");
c=s.nextChar();
System.out.println("Enter outside character");
char o=s.nextChar();
Hollowsquare(Length, c, o);
break;
case 3: c="X";
square(Length, c);
break;
case 4:
c="|";
square(Length, c);
break;
case 5:
c="-";
square(Length, c);
break;
case 6:
c="/";
square(Length, c);
break;
case 7:
Numbersquare(Length,x );
break;
case 8: System.out.println("Enter number to multipled");
x=s.nextChar();
Numbersquare(Length, x );
break;
default: System.out.print("Invalid choice");
break;
}
}
void square (int Length, char c)
{
for (int i = 0; i < Length; i++) {
for (int j = 0; j < Length; j++) {
System.out.print(c);
} System.out.print();
}
void Hollowsquare (int Length, char c, chat o)
{
for (int i = 0; i < Length; i++)
{
for (int j = 0; j < Length; j++) {
if (i == 1 || i == Length || j == 1 || j == Length)
System.out.print(c);
else
System.out.print(o);
} System.out.print();
}
void Numbersquare (int Length)
{
int c,x=1;
for (int i = 0; i < Length; i++) {
for (int j = 0; j < Length; j++) {
System.out.print(c*x);
} System.out.print();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.