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


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

Re: A new small quiz question

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: A new small quiz question
Date Wed, 16 Aug 2017 08:30:57 -0400
Organization A noiseless patient Spider
Lines 27
Message-ID <on1dm4$6bp$1@dont-email.me> (permalink)
References <quiz-20170816122427@ram.dialup.fu-berlin.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Wed, 16 Aug 2017 12:26:44 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="35551023f947087197aa6b1c652ca93b"; logging-data="6521"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18SCgKrAUFxJDBjYKITNu8C"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1
In-Reply-To <quiz-20170816122427@ram.dialup.fu-berlin.de>
Content-Language en-US
Cancel-Lock sha1:B0aCLusCROECroPokaM0eC+y4dM=
Xref csiph.com comp.lang.java.programmer:37255

Show key headers only | View raw


On 8/16/2017 7:25 AM, Stefan Ram wrote:
>    Can you predict (without trying it out) what the output
>    of the following program is?

     Yes.

> public final class Main
> {
>    private static int f( final int i )
>    { java.lang.System.out.println( i ); return i; }
> 
>    public static void main( final java.lang.String[] args )
>    { int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
> 
>      x[ f( 0 )]= x[ f( 1 )]= x[ f( 2 )];
> 
>      java.lang.System.out.println( x[ 0 ]); }}

     Unlike many of your other quizzes and curiosities, this
one appears to have some pedagogic value.  However, I'm sure
the lesson could be conveyed with less obfuscation.  Also,
were I teaching Java I would follow the advice of JLS 15.7
and discourage students from employing this linguistic oddity.

-- 
esosman@comcast-dot-net.invalid
Twelve hundred fifty-three days to go.

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


Thread

Re: A new small quiz question Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-08-16 08:30 -0400

csiph-web