java help

shalafi

Veteran X
public class Stars2
{
public static void main (String[] args)
{
for(int space = 10;space > row; space--)
System.out.print(" ");
{
for(int star=1;star<=row;star++)
System.out.print("*");
System.out.println();

}
}
}

Whats wrong with the 2 for statements I keep getting cannot resolve symbol:[
btw I know its probably remedial programming, but Im not to good at it.
 
shalafi said:
Code:
public class Stars2
{
	public static void main (String[] args)
	{
		for(int space = 10;space > row; space--)
		System.out.print(" ");
		{
			for(int star=1;star<=row;star++)
			System.out.print("*");
			System.out.println();
			
		}
	}
}

Whats wrong with the 2 for statements I keep getting cannot resolve symbol:[
btw I know its probably remedial programming, but Im not to good at it.
Try declaring row.
 
Question, since the brackets are left out for the 2nd for statement does the 2nd for statement iterate through the next 2 statements ? Or just the first ? If just the first, that 2nd line never gets executed.
 
Good Question, I dont guess it does because its not running what I want it to. Its printing a single line of stars when I want it to print 10 rows of different amounts of stars in each.
 
I thought so too...it just looks weird, but I was skeptic to say it was thoroughly un-appealing to the eye, but with Java I've found sometimes weird things just work.

As for the first for statement, typically you don't have a statement until after the first bracket, but I'm guessing this is somehow working with the blank space printing prior to the first bracket.
 
Maybe use this:

public class Stars2
{
public static void main (String[] args)
{
static int row = 5;

for(int space = 10;space > row; space--)
{
System.out.print(" " );
}

for(int star=1;star<=row;star++)
{
System.out.print("*" );
System.out.println();
}
}
}
 
Molim your code just changed the stars from going horizontally to vertically, and you cant start the expression with static.
 
This is what it would look like through what I posted, but I can't see this is what you want.

//Output starts here





*

*

*

*

*

//Output ends here
 
Back
Top