Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that produces the following output using nested for loops: +------+ | ^^ | | ^ ^ | |^ ^| | ^^ |

Write a program that produces the following output using nested for loops:

+------+

| ^^ | | ^ ^ | |^ ^| | ^^ | | ^ ^ | |^ ^| +------+ | vv | | v v | |v v| | vv | | v v | |v v| +------+

My answer:

public class Pattern{

public static void main(String args[]){

tophead();

middle();

middle();

tophead();

middlev();

middlev();

tophead();

}

public static void tophead(){

System.out.println("+------+");

}

public static void middle(){

for(int i=0;i<3;i++){

System.out.print("|");

for(int j=2;j<=j-i;j--){

System.out.print(" ");

}

System.out.print("^");

for(int k=0;k<=2i-1;k++;){

System.out.print(" ");

}

System.out.println("^");

for(int l=2;l<=l-i;l--){

System.out.print(" ");

}

System.out.print("|");

}

}

public static void middlev(){

for(int i=0;i<3;i++){

System.out.print("|");

for(int j=2;j<=j-i;j--){

System.out.print(" ");

}

System.out.print("v");

for(int k=0;k<=2i-1;k++;){

System.out.print(" ");

}

System.out.print("v");

for(int l=2;l<=l-i;l--){

System.out.print(" ");}

System.out.print("|");

}

}

}

results :

Pattern.java:22: error: ';' expected for(int k=0;k<=2i-1;k++;){ ^ Pattern.java:22: error: not a statement for(int k=0;k<=2i-1;k++;){ ^ Pattern.java:22: error: ')' expected for(int k=0;k<=2i-1;k++;){ ^ Pattern.java:22: error: illegal start of expression for(int k=0;k<=2i-1;k++;){ ^ Pattern.java:39: error: ';' expected for(int k=0;k<=2i-1;k++;){ ^ Pattern.java:39: error: not a statement for(int k=0;k<=2i-1;k++;){ ^ Pattern.java:39: error: ')' expected for(int k=0;k<=2i-1;k++;){ ^ Pattern.java:39: error: illegal start of expression for(int k=0;k<=2i-1;k++;){ ^ 8 errors 

can anyone help me finding out what's the matter..?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Science For Dummies

Authors: Lillian Pierson ,Jake Porway

2nd Edition

1119327636, 978-1119327639

More Books

Students also viewed these Databases questions