Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started