[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error in the ouput

Posted on 2011-04-30
5
Medium Priority
?
320 Views
Last Modified: 2013-11-23
the output should be 13579., but im still getting an error, can somebody help me out?
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);
      }
}

111.JPG
0
Comment
Question by:waltbaby315
  • 3
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 35499220
the code you have posted is not the same as what is giving the error
check you don't have 2 versions of the class
0
 

Author Comment

by:waltbaby315
ID: 35499226
I posted the error code again. This is the error it give me?
000.JPG
0
 
LVL 92

Expert Comment

by:objects
ID: 35499232

the code in the error message is different from the code

In the code you posted the for loop looks like  

>             for (int i = 1; i <= 9; i += 2)

Check the contents of Examplechapter6ques7.java
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 35499252
The code you posted compiles successfuly and gives expected result:
Paste this code into the files as you have it in the question,
compile and excute it, and it will work.

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);
      }
}

 

Open in new window


Output:
13579

Open in new window

0
 
LVL 92

Expert Comment

by:objects
ID: 35499301
I already told you that?? Why did you accept that comment?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question