Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #29373

Help understanding methods

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Scott Dunning <scottwd01@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Help understanding methods
Date Sun, 27 Jul 2014 17:46:53 -0700
Organization A noiseless patient Spider
Lines 44
Message-ID <lr46d1$ub3$1@dont-email.me> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 28 Jul 2014 00:44:17 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="11828741c91d0da908948c6ecdf164c7"; logging-data="31075"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dVGBGN13vMQ0uPfybm2OZPuu2gNsXXOw="
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.3.0
Cancel-Lock sha1:XSc36DVTxN6lGWS2uxzWylfx3Hc=
Xref csiph.com comp.lang.java.programmer:29373

Show key headers only | View raw


So, I'm very new to Java, I have a summer college course and we're on 
functions (methods) and I'm having a bit of trouble understanding them.

There is a question on a lab I'm having a little trouble with:

"Write a method called MaxOfThree that accepts three integer parameters 
and returns the largest of the three."

This is what I have so far but I'm not sure whats wrong. I added the 
print statement at the end because I wasn't getting a return value when 
I ran it but now I'm getting errors and it's not compiling. If you could 
help me understand methods a bit more I'd greatly appreciate it. For 
instance how the parameters work and calling it and if what's included 
in the function call is correct and how that works. I just get so 
confused when I read through the material and was hoping for an 
explanation in more layman's terms. Thanks for any help, here is what I 
have so far.

public class Test {

     public static void main(String[] args) {
         int a = 2, b = 3, c = 4;
         int maxValue = max3(a, b, c);
     }

     public static int max3(int a, int b, int c) {
         int max = a;
         if (b > max) max = b;
         if (c > max) max = c;
         return max;
         System.out.println(max);
     }
}


Here are the errors I'm receiving just in case...

Test.java:16: error: unreachable statement
            System.out.println(max);
            ^
Test.java:17: error: missing return statement
         }
         ^
2 errors

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Help understanding methods Scott Dunning <scottwd01@gmail.com> - 2014-07-27 17:46 -0700
  Re: Help understanding methods Knute Johnson <eternal@knutejohnson.com> - 2014-07-27 18:13 -0700
    Re: Help understanding methods Scott Dunning <scottwd01@gmail.com> - 2014-07-27 18:19 -0700
      Re: Help understanding methods Knute Johnson <eternal@knutejohnson.com> - 2014-07-27 18:49 -0700
        Re: Help understanding methods Knute Johnson <eternal@knutejohnson.com> - 2014-07-27 21:36 -0700
  Re: Help understanding methods Martin Gregorie <martin@address-in-sig.invalid> - 2014-07-28 01:18 +0000
  Re: Help understanding methods Scott Dunning <scottwd01@gmail.com> - 2014-07-27 18:56 -0700
    Re: Help understanding methods "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-07-28 12:07 +0100
      Re: Help understanding methods "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-07-28 12:44 +0100
  Re: Help understanding methods Roedy Green <see_website@mindprod.com.invalid> - 2014-07-28 07:20 -0700
  Re: Help understanding methods Josip Almasi <joe@vrspace.org> - 2014-07-28 21:29 +0200

csiph-web