Results 1 to 9 of 9
  1. #1
    Petee is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default whats wrong with this code?

    I have just started learning java and I have tried to make this simple thing but it doesnt work, when i try to compile it there are apparently 2 errors:

    class apples{
    public static void main (string args[]) {
    system.out.println("hello!!");
    }
    }

    One of the errors is the '.' after system, and i forgot the other one.

    Help please? :(

  2. #2
    Petee is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Re: whats wrong with this code?

    nvm, i just found out that string needs a capital 'S' and so does system. :)

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default Re: whats wrong with this code?

    And better make that:

    Java Code:
    public class Apples {  ... }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Petee is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Re: whats wrong with this code?

    import java.util.Scanner;
    class apples{
    public static void main(String args[]){
    Scanner p = new Scanner(System.in);
    double fnum, snum, answer;
    System.out.println("Enter first number: ");
    fnum = p.nextDouble();
    System.out.println("Enter second number: ");
    snum = p.nextDouble();
    answer = fnum + snum;
    System.out.println(answer);
    }
    }

    What is wrong with that code? Eclipse says that the second line is wrong but I don't see any problem with it...
    Last edited by Petee; 09-30-2011 at 01:08 PM.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default Re: whats wrong with this code?

    Quote Originally Posted by Petee View Post
    What is wrong with that code? Eclipse says that the second line is wrong but I don't see any problem with it...
    Wouldn't it be nice if you tell use exactly what Eclipse had told you. It might've said "I don't like fruit" in which case we all would have a laugh and suggest that you install a fresh copy of Eclipse, but it probably didn't say that; we are curious to know; programming is an exact profession and telling us that something else told you that something "is wrong" doesn't help us to help you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Petee is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

    Default Re: whats wrong with this code?

    When i put my mouse over the X it says 'the type apples is already defined' and when i try to run the program it just says an error exists.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,570
    Rep Power
    23

    Default Re: whats wrong with this code?

    What happens when you compile the program?

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,000
    Blog Entries
    7
    Rep Power
    20

    Default Re: whats wrong with this code?

    Quote Originally Posted by Petee View Post
    When i put my mouse over the X it says 'the type apples is already defined' and when i try to run the program it just says an error exists.
    You have corrupted Eclipse's workspace a bit by leaving another apples.class or even apples.java file there. Go to Project>Clean ... and clean all your projects in your workspace and see what Eclipse has to say about that.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Petee is offline Member
    Join Date
    Sep 2011
    Posts
    10
    Rep Power
    0

Similar Threads

  1. whats wrong with my code
    By naved in forum New To Java
    Replies: 5
    Last Post: 07-15-2011, 02:06 AM
  2. Whats wrong with my code
    By zit1343 in forum New To Java
    Replies: 9
    Last Post: 01-24-2011, 01:06 AM
  3. whats wrong with this code
    By hamzeeco in forum Java Applets
    Replies: 1
    Last Post: 12-31-2010, 02:19 PM
  4. Whats wrong with this code???
    By javanew in forum New To Java
    Replies: 4
    Last Post: 03-28-2010, 05:46 PM
  5. Whats wrong with this code?
    By bbtgirl in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 03:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •