0

If someone could help me out here I would really appreciate it...
I have to get this code running for my programming class and i keep getting same symbol error here is the code:

public class fourseventeen {
  public void main(String[] args) {    
    

    int j = 0;
    int sum = 0;
    
    for (int i = 0; i < 10; i++)
      sum += i;

    if (i < j)
    
      System.out.println(i);
    else
      System.out.println(j);

    while (j < 10)
    {
      j++;
    };

    do {
      j++;
    } while (j < 10);
  }
}
3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by lucstrato
0

It would help if you declared main correctly, as

public static void

Also, you might want to check that the variable 'i' doesn't go out of scope after the for loop.

0

Okay, I fixed the main and this is what im at right now:

public class fourseventeen {
  public static void main(String[] args) {    
	
	int j = 0;
	int sum = 0;
	
	
	for (int i = 0; i < 10; i++)
		sum += i;
		
	if (i < j)
		System.out.println(i);
	else
		System.out.println(j);
		
	while (j < 10)
	{
		j++;
	};
	
	do {
		j++;
		
	}	while (j < 10);
  }
 }

Im currently receiving the following errors in my build output:
--------------------Configuration: <Default>--------------------
C:\java\fourseventeen.java:11: cannot find symbol
symbol : variable i
location: class fourseventeen
if (i < j)
^
C:\java\fourseventeen.java:12: cannot find symbol
symbol : variable i
location: class fourseventeen
System.out.println(i);
^
2 errors

0

your variable i is undefined at those lines the compiler is pointing out. perhaps your "for" loop is supposed to encompass more than 1 statement.

0

Okay,
I added {} in my for loop and that fixed the problem. Thanks all for the responses much appreciated.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.