Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+10 votes

I tried to write a program for question 12 in last year test. But I encounter an error in my program, and I do not know why it is wrong and how to fix it.

1.for (int line = 1; line <= 6; line++) {
2.		for (int star = 1; star <= line; star++) {
3.			System.out.print("*");
4.		}
5.		System.out.print(-1*line+7);
6.		}
7.		for (int hash = 1; hash <= -2*line+14; hash++) {
8.			System.out.print("#");
9.		}
10.	System.out.println();

eclipse show that I have an error in line 7: Multiple markers at this line

                                                         - line cannot be resolved to a 
                                                            variable
asked ago in CSC211_Winter2018 by (1.2k points)
edited ago by

2 Answers

+8 votes
 
Best answer

The curly brace on line 6 is ending the outer for loop with loop control variable line. The variable line is not in scope beyond the body of the for loop in which it is defined.

The outer for loop should end after line 10.

You also need "*" in the first print statement as Louis mentioned.

answered ago by (1.1k points)
selected ago by
+4 votes

I'm not sure why it is giving you this error. I entered the same code into eclipse, and while it did not give the desired outcome, it was able to complete without errors (make sure to put the * in between the quotations in line 2.

Did you copy and paste this over? I suggest you use the code format for entering questions into this forum, just click on the {} symbol and then paste your code into it and it will paste just like it looks in eclipse with the same formatting. It will be easier to de-bug that way.

answered ago by (3.8k points)
+2

Also, this code can be much simpler if you begin the integer "line" at 6 so the initial for statement is

for (int line = 6; line >= 1; line--)
...