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


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

Re: 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 Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Help understanding methods
Date Mon, 28 Jul 2014 01:18:51 +0000 (UTC)
Organization A noiseless patient Spider
Lines 33
Message-ID <lr48dr$4ur$1@dont-email.me> (permalink)
References <lr46d1$ub3$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Mon, 28 Jul 2014 01:18:51 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="e5160e2be48f1ea550cf61512446f525"; logging-data="5083"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hVa4kArCrH7LJG/6D8qonLs79biNSBfk="
User-Agent Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2)
Cancel-Lock sha1:kGsjE4Z5YUIJu9sYfuJx/YTr8yw=
Xref csiph.com comp.lang.java.programmer:29376

Show key headers only | View raw


On Sun, 27 Jul 2014 17:46:53 -0700, Scott Dunning wrote:

> 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);
>      }
> }
>
The compilation error occurred because the print statement is after the 
return statement. The compiler is telling you that it can never be 
executed because the preceding return will have forced an exit from the 
method before the print statement is executed.

The other problem is that, without a print statement in main() you'll 
never know what max3() returned.  Fix those two problems and it will 
work, though calling max3() a few more times (and displaying the result 
each time) with different arguments values with the values in a different 
order will give you more confidence in its correctness.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | 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