output error

Can someone tell me what Im doing wrong to get this error?

class Examplechapter6ques7
{
public static void main(String[] args)
{

int sum = 0;
int i;
for(int i;i<=9;i+=2)result=result+i;
System.out.println(""+i);
}
}
today1.JPG
waltbaby315Asked:
Who is Participating?
 
objectsCommented:

> he worksheet I have it should be 13579

change it to use string, that should give you the result you need


public class Examplechapter6ques7 {
      public static void main(String[] args) {

            String result = "";
            for (int i = 1; i <= 9; i += 2)
                  result = result + i;
            System.out.println(result);
      }
}
0
 
objectsCommented:
you don't declare result


class Examplechapter6ques7
{
public static void main(String[] args)
{

int sum = 0;
int i;
int result = 0;
for(int i;i<=9;i+=2)result=result+i;
System.out.println(""+i);
}
}
0
 
objectsCommented:
you also deslare i twice


class Examplechapter6ques7 {
      public static void main(String[] args) {

            int sum = 0;
            int result = 0;
            for (int i = 0; i <= 9; i += 2)
                  result = result + i;
            System.out.println("" + result);
      }
}

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
waltbaby315Author Commented:
Using Savant first example I got an error. Using Savant second example I got an output of 20, the worksheet I have it should be 13579 and it uses both result = result + i; Any reson why they dont use both?
71.JPG
0
 
objectsCommented:
see my second comment
0
 
waltbaby315Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.