Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31441
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Jeff Higgins <jeff@invalid.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Simple if-exercises |
| Date | Thu, 02 Apr 2015 10:53:33 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 36 |
| Message-ID | <mfjl6q$f61$1@dont-email.me> (permalink) |
| References | <if-20150402020010@ram.dialup.fu-berlin.de> <mfjhvg$1ka$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Thu, 2 Apr 2015 14:54:18 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="c50a9e5d554cfaba13eda1c71e805135"; logging-data="15553"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/V6aBf0ToK8aLi5V0rIgy4TR6D5WoY9cI=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.5.0 |
| In-Reply-To | <mfjhvg$1ka$1@dont-email.me> |
| Cancel-Lock | sha1:kdhuM5ka7dW6MexsQJ2PaCah8SU= |
| Xref | csiph.com comp.lang.java.programmer:31441 |
Show key headers only | View raw
On 04/02/2015 09:58 AM, Jeff Higgins wrote:
> On 04/01/2015 08:10 PM, Stefan Ram wrote:
>> I was looking for very simple if-exercises.
>>
>> I usually found exercises like this:
>>
>> »Print "positive" if x > 0, "non-positive", otherwise.«
>>
>> The expected answer would be
>>
>> if( x > 0 )
>> System.out.println( "positive" );
>> else
>> System.out.println( "non-positive" );
>>
>> However, I already have taught »?:«, so the better
>> (shorter) solution would be:
>>
>> System.out.println( ( x > 0 ? "" : "non-" )+ "positive" );
>>
>> . Do you know a very simple if-exercise whose solution
>> cannot be written more tersely with the ternary operator
>> or where the formulation with »if« is clearly better than
>> with the ternary operator?
>>
>> Knowledge that can be assumed: calls and declarations of
>> static methods, +, -, *, /, usage of variables, declarations
>> of local variables, boolean, int, double, String, literals,
>> the block {...}, ?:, <, >, <=, >=, !=, ==.
>>
> Why don't we have a Quinary operator?
> x ? y LT : EQ : GT
>
Or Senary might be better - avoids an unchecked exception.
x ? y LT : EQ : GT : NC
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Simple if-exercises Jeff Higgins <jeff@invalid.invalid> - 2015-04-02 09:58 -0400
Re: Simple if-exercises Jeff Higgins <jeff@invalid.invalid> - 2015-04-02 10:53 -0400
Re: Simple if-exercises Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-02 15:08 -0400
Re: Simple if-exercises Gene Wirchenko <genew@telus.net> - 2015-04-02 16:46 -0700
Re: Simple if-exercises v_borchert@despammed.com (Volker Borchert) - 2015-04-03 06:29 +0000
Re: Simple if-exercises Martin Gregorie <martin@address-in-sig.invalid> - 2015-04-03 10:29 +0000
Re: Simple if-exercises v_borchert@despammed.com (Volker Borchert) - 2015-04-03 18:05 +0000
Re: Simple if-exercises Martin Gregorie <martin@address-in-sig.invalid> - 2015-04-03 19:31 +0000
Re: Simple if-exercises Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-03 16:07 -0400
Re: Simple if-exercises Martin Gregorie <martin@address-in-sig.invalid> - 2015-04-03 21:45 +0000
Re: Simple if-exercises v_borchert@despammed.com (Volker Borchert) - 2015-04-03 23:49 +0000
Re: Simple if-exercises Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-03 07:38 -0400
Re: Simple if-exercises Jeff Higgins <jeff@invalid.invalid> - 2015-04-03 20:06 -0400
csiph-web