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.

Page 2 of 2 FirstFirst 12
Results 26 to 44 of 44

Thread: return outside method

  1. #26
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    well, when i try to add the stuff it makes ot worse

  2. #27
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: return outside method

    Add what "stuff"? You need to be more specific in your answers.
    Which error are you working on?

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  3. #28
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    i add braces and it makes it worse

  4. #29
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: return outside method

    Where are you adding your braces? To which part(s) of the code?

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  5. #30
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    the end of the quoted line like mine says to

  6. #31
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: return outside method

    Can you post the code with the updates? It's impossible
    to guess what is going on without any visual aid. Also
    comment the line(s) that have errors when you compile it
    and if possible the errors also.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  7. #32
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    String bottlewordString(int bottleNumber);

  8. #33
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: return outside method

    What does the error message actually say? If that
    is a method parameter, then it should not have the
    semicolon. Can you not show more code than that?

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  9. #34
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    the error message says (exact)

    error: ';' expected
    String bottlewordString(int bottleNumber);
    ^

  10. #35
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: return outside method

    Going by the last piece of code you posted:

    * why are there semicolons after your 'if' statements?

    * Have you solved the "class needs to be in own file" error?

    * Again - the semicolon after the method parameter is going to cause errors.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  11. #36
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    i thought i needed the semicolons and i havent solved the second problem. on the last one i thought i needed the semicolon because of the error message.

  12. #37
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: return outside method

    If you put semicolons after an 'if' statement, the program is always
    going to evaluate the statement as true - or preform some other
    undefined behaviour.

    Putting a semicolon after a method parameter should always cause
    a logic or compilation error. If you place the BeerSong class in it's
    own file (which was the first problem) most of the errors will be
    easier to understand.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  13. The Following User Says Thank You to Ada Lovelace For This Useful Post:

    lucas29 (July 31st, 2014)

  14. #38
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    i think that'll help me, thank you

  15. #39
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: return outside method

    Quote Originally Posted by Ada Lovelace View Post
    If you put semicolons after an 'if' statement, the program is always
    going to evaluate the statement as true - or preform some other
    undefined behaviour.
    Nope, not true and the behaviour will always be defined.
    if(3 == 5);
    This will never be true regardless if the semicolon is there or not. However the presence of the semicolon signals the end of the if statement. The below code is the equivalent.
    if(3 == 5) {
        ;
    }
    This effectively says if the condition is true do nothing. What causes the confusion is that the code following the semicolon (which people assume is inside the if statement) is actually outside the if statement and will always be executed regardless of the condition in the if statement.
    Improving the world one idiot at a time!

  16. The Following User Says Thank You to Junky For This Useful Post:

    Ada Lovelace (August 1st, 2014)

  17. #40
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    um, so what do u want me to do?

  18. #41
    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: return outside method

    What we want you to do: Read and apply the advice given, make progress, report back with your results, updated code, new errors, and new questions. We've been over this before. We're not going to write it for you.

  19. #42
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: return outside method

    Is this a college assignment? If so when is/was it due?
    You have been working on this for over two weeks now at
    least.

    Have you spoken to your professor or teaching assistant about it?
    Have you been given extensions or guidelines to follow?

    Read the assignment question from the text book and try to work it
    out on pen and paper first. If you work out what is supposed to happen,
    write it in pesudocode (spelling?). Then slowly translate that code into
    executable Java statements. Follow the guidelines from Greg, myself and
    others.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  20. #43
    Member
    Join Date
    Jul 2014
    Posts
    48
    My Mood
    Confused
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: return outside method

    i have no teacher, except a book

  21. #44
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: return outside method

    Have you made any progress since the last problems?
    Are you getting any new errors or problems? Have you
    resolved any of the ones posted previously?

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: May 27th, 2014, 07:39 PM
  2. Please help with method return statement!
    By brobertson300 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 3rd, 2014, 07:10 AM
  3. can i return two values from a return method?
    By tonu in forum Object Oriented Programming
    Replies: 4
    Last Post: January 1st, 2014, 11:02 AM
  4. return from a method
    By MHS in forum Java Theory & Questions
    Replies: 1
    Last Post: June 15th, 2013, 01:06 PM
  5. Method return value(s)
    By mwr76 in forum Loops & Control Statements
    Replies: 3
    Last Post: October 2nd, 2011, 02:38 PM