Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23
Like Tree1Likes

Thread: Help with finishing code

  1. #21
    hockey101 is offline Member
    Join Date
    Dec 2012
    Posts
    44
    Rep Power
    0

    Default Re: Help with finishing code

    so at the end, I put System.out.println(result); but now its saying that result hasn't been initialized.

  2. #22
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,028
    Rep Power
    4

    Default Re: Help with finishing code

    The compiler complains that it might nog be initialized because the compiler doens't know if the result will ever be set. YOU know that because one of the if's will always be hit, but the compiler doesn't. Add = null to initilaize result to null.
    Java Code:
    Rational result = null;
    if (...) {
       result = something();
    }
    else if (...) {
       result = something2();
    }
    print result here.
    Last edited by SurfMan; 01-11-2013 at 05:48 PM.

  3. #23
    hockey101 is offline Member
    Join Date
    Dec 2012
    Posts
    44
    Rep Power
    0

    Default Re: Help with finishing code

    Ok i fixed the problem. My problem was the last else if statement. I didn't need the if on the else because I already stated earlier above that I only wanted the user to choose an operation with the corresponding numbers of 1 through 4. So thanks everyone for all there help.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Need Help Finishing Method - Program Attached
    By jimmyo88 in forum New To Java
    Replies: 1
    Last Post: 01-23-2012, 03:47 PM
  2. so i need help finishing my histogram plz help
    By cachico12 in forum New To Java
    Replies: 1
    Last Post: 05-10-2011, 07:04 AM
  3. Replies: 11
    Last Post: 04-26-2011, 08:55 AM
  4. finishing up a DB/Java exercise
    By hayden06f4i in forum New To Java
    Replies: 47
    Last Post: 12-12-2010, 10:57 PM

Posting Permissions

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