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 9 of 9

Thread: Big Rookie Question - New to Java, small problem Help appreciated!

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Big Rookie Question - New to Java, small problem Help appreciated!

    Hey guys im really new to java, trying to learn it a bit by myself I appreciate help with this!

    This is my code:

    Im getting an error when trying to run it (With Netbeans IDE)

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable number is already defined in method main(java.lang.String[])
    	at Comparison.main(Comparison.java:10)
    Java Result: 1

    import java.util.Scanner;
     
    public class Comparison
    {
        public static void main( String[] args )
        {
         Scanner input = new Scanner( System.in );
     
         int number 1;
         int number 2;
     
         System.out.print( "Enter First Integer: " );
         number1 = input.nextInt();
     
         System.out.print( "Enter First Integer: " );
         number1 = input.nextInt();
     
         if ( number1 == number2 )
             System.out.printf( "%d == %d\n", number1, number2 );
     
         if ( number1 != number2 )
             System.out.printf( "%d != %d\n", number1, number2 );
     
         if ( number1 < number2 )
             System.out.printf( "%d < %d\n", number1, number2 );
     
         if ( number1 > number2 )
             System.out.printf( "%d > %d\n", number1, number2 );
     
         if ( number1 <= number2 )
             System.out.printf( "%d <= %d\n", number1, number2 );
     
         if ( number1 >= number2 )
             System.out.printf( "%d >= %d\n", number1, number2 );
        }
    }


  2. #2
    Junior Member
    Join Date
    Sep 2013
    Location
    Denmark
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Big Rookie Question - New to Java, small problem Help appreciated!

    The following is not legal syntax:
    int number 1;
    int number 2;

    it has to be
    int number1;
    int number2;

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Big Rookie Question - New to Java, small problem Help appreciated!

    Thanks so much!!

    --- Update ---

    Side Note: now it allowing it to run, most errors have disapeared but now I am getting this when running
    run:
    Enter First Integer: 3
    Enter First Integer: 1
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - variable number2 might not have been initialized
    at Comparison.main(Comparison.java:18)
    Java Result: 1

  4. #4
    Junior Member
    Join Date
    Sep 2013
    Location
    Denmark
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Big Rookie Question - New to Java, small problem Help appreciated!

    For some reason I can't edit prior post, you never initialise number 2 either so all things you do with it will never work

    --- Update ---

    What is wrong with the edit function?

    Anyways:
         System.out.print( "Enter First Integer: " );
         number1 = input.nextInt();
     
         System.out.print( "Enter First Integer: " );
         number1 = input.nextInt();

    Should be:
         System.out.print( "Enter First Integer: " );
         number1 = input.nextInt();
     
         System.out.print( "Enter Second Integer: " );
         number2 = input.nextInt();

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Big Rookie Question - New to Java, small problem Help appreciated!

    Thank you so much tools! all works now, much appreciated

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Big Rookie Question - New to Java, small problem Help appreciated!

    What is wrong with the edit function?
    A forum bug that is being worked, or so we've been told. A workaround is to right click on the desired function (like Edit) and select open in a new tab or window.

  7. #7
    Junior Member
    Join Date
    Sep 2013
    Location
    Denmark
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Big Rookie Question - New to Java, small problem Help appreciated!

    Thank you

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Big Rookie Question - New to Java, small problem Help appreciated!

    @tools Please read: The problem with spoonfeeding
    We all appreciate your offers to help others. At the same time we try not to give solutions, but hints to help the OP find their own solution.

  9. #9
    Junior Member
    Join Date
    Sep 2013
    Location
    Denmark
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Big Rookie Question - New to Java, small problem Help appreciated!

    @jps Thank you hand't seen that

Similar Threads

  1. Simple question about a small program
    By azizmaiden in forum Java Theory & Questions
    Replies: 5
    Last Post: March 2nd, 2013, 05:52 PM
  2. Rookie here, need help with sum of digits program
    By wkellogg10 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2013, 07:25 PM
  3. Big-O Notation question
    By colerelm in forum Java Theory & Questions
    Replies: 1
    Last Post: November 28th, 2011, 09:52 PM
  4. Small problem in big code, not sure why
    By diesal11 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 16th, 2011, 10:25 AM
  5. Big-O Question
    By Kumarrrr in forum Algorithms & Recursion
    Replies: 2
    Last Post: March 3rd, 2010, 07:46 AM