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


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

Re: Java puzzler

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!news.albasani.net!.POSTED!not-for-mail
From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Java puzzler
Date Tue, 10 May 2011 20:16:06 -0400
Organization albasani.net
Lines 47
Message-ID <iqckg3$35e$1@news.albasani.net> (permalink)
References <871987d9-1034-441d-9d33-b2dd6b4de234@glegroupsg2000goo.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.albasani.net KfWRiWEWsQzRGckAFNTEQpd6iZ26Ka4SVyCDV9Fdj5+myM7ikVT92FLVGVxCKgaCP3BDzr+EVJv3H52ubG0zcg==
NNTP-Posting-Date Wed, 11 May 2011 00:16:03 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="iQ0Lxig6T+0/CNl8/NV84WaNryktVkKa6D3tgZ7KglAAl2/ijf7M4HmnI0wBaptk29Bjik7UVWxs7zhvZd4tGXHxE+XDrDCoUGMg7y4P5OxptCmhdmokUTwK0wpAxF2s"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10
In-Reply-To <871987d9-1034-441d-9d33-b2dd6b4de234@glegroupsg2000goo.googlegroups.com>
Cancel-Lock sha1:HVmif3zC7jP89xgpCBOUHaH6IAE=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3942

Show key headers only | View raw


On 05/10/2011 07:36 PM, Gábor Bakos wrote:
> Hello,
>
>     Sorry if this is already a known behaviour, but first I found this really strange:
> int x = 0;
> x += 0.5;
> What does the code snippet above do:
>    - compile and run without error result is
>        - 0
>        - 1
>        - depends on the strict or nonstrict computation
>    - compile and ArithmeticException is thrown
>    - does not compile (Type mismatch: cannot convert from double to int)

What happened for you when you tried it?

> For those who want to know the answer check this[1] and this[2].
> ...
> [1]: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.26.2
> [2]: http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.3

What precisely did you find strange?

<sscce source="com/lewscanon/eegee/Conversioneer.java" >
package com.lewscanon.eegee;
/**
  * Conversioneer.
  */
public class Conversioneer
{
   /**
    * main.
    * @param args String []
    */
   public static void main( String [] args )
   {
     int x = 0;
     x += 0.5;
     System.out.println( "x = "+ x );
   }
}
</sscce>

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

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


Thread

Java puzzler Gábor Bakos <aborgabor@gmail.com> - 2011-05-10 16:36 -0700
  Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-10 20:16 -0400
  Re: Java puzzler Roedy Green <see_website@mindprod.com.invalid> - 2011-05-11 03:03 -0700
    Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-11 09:07 -0400
      Re: Java puzzler markspace <-@.> - 2011-05-11 08:10 -0700
        Re: Java puzzler Roedy Green <see_website@mindprod.com.invalid> - 2011-05-11 22:02 -0700
          Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-12 08:35 -0400
            Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 08:13 -0700
              Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-12 12:11 -0400
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 18:28 -0700
          Re: Java puzzler Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-05-12 10:14 -0400
      Re: Java puzzler Roedy Green <see_website@mindprod.com.invalid> - 2011-05-11 21:49 -0700

csiph-web