Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Dont laugh at me

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dont laugh at me

    I have started using Java at university; Lecturer cant be found and this is really annoying me.

    class  SimpleAdd {
    	public static void main(String[] args) 	{
    		int x;
    		int y;
    		int sum;
    		x = <>;
    		y = <>;
    		sum = x + y;
    		System.out.println(sum);
    	}
    }

    X and Y both need to have values right? So when I enter 1 and 4 like so:

    class SimpleAdd {
    public static void main(String[] args) {
    int x;
    int y;
    int sum;
    x = <int 1>;
    y = <int 4>;
    sum = x + y;
    System.out.println(sum);
    }
    }

    It compiles no problem - but when I ask it to run it tells me:

    H:\>cd javame-sdk

    H:\javame-sdk>javac SimpleAdd.java
    SimpleAdd.java:6: > expected
    x = <int 1>;
    ^
    SimpleAdd.java:6: illegal start of expression
    x = <int 1>;
    ^
    SimpleAdd.java:6: illegal start of expression
    x = <int 1>;
    ^
    SimpleAdd.java:7: > expected
    y = <int 4>;
    ^
    SimpleAdd.java:7: illegal start of expression
    y = <int 4>;
    ^
    SimpleAdd.java:7: illegal start of expression
    y = <int 4>;
    ^
    6 errors

    Can anyone help - I know its a basic problem, but without covering the basics how can I progress to more advanced things??

    Ben
    Last edited by Freaky Chris; October 1st, 2009 at 07:42 AM.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Dont laugh at me

    Surely that cant compile, its supposed to look something like this.

    x = 1;
    y = 4;

    Oh and javac is the compile btw, so if thats the one complaining then its a compilation error.

    // Json

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Dont laugh at me

    Btw which university are you at?
    chris[at]javaprogrammingforums[dot]com

    Prifysgol Bangor University, North Wales

  4. #4
    Junior Member
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Dont laugh at me

    The "int" bit shouldn't be there - it compiles with the just the number value - my bad

    I will have a blast now with it; looking the way you suggested,

    Ben

    Hull university btw - why near by?

  5. #5
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Dont laugh at me

    Are you a Hull rugby fan then?

    // Json

  6. #6
    Junior Member
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Dont laugh at me

    haha,good luck!