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


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

Re: Java puzzler

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Java puzzler
Date 2011-05-10 20:16 -0400
Organization albasani.net
Message-ID <iqckg3$35e$1@news.albasani.net> (permalink)
References <871987d9-1034-441d-9d33-b2dd6b4de234@glegroupsg2000goo.googlegroups.com>

Show all headers | 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