• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

asking about java

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there,
hope u r doin� fine. I have some problem in the coming topic n I hope that u will solve my problem,given below:
1. int I=45;
I=(int)(i/0.0);
//output is given as 214474836 which is the maximum value of the integer
why output is the maximum integer number?
2. byte b=45;
b=(byte)(i/0.0);
// output is given as �1
sir my question is that while applying int output was the maximum value which was given n in the case of byte or short the output is �1.
sir I hope that u will solve it .thank u very much in advance.
take care
with regards
kumar abhay
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1. int I=45;
I=(int)(i/0.0);
//output is given as 214474836 which is the maximum value of the integer
why output is the maximum integer number?


Kumar
In floating point operations any division of a non-zero finite number by 0 will reult in signed infinity. Then when you cast it to an int you follow the rules of the JLS section 5.1.3 and the result is converted to the maximum value of an int.


2. byte b=45;
b=(byte)(i/0.0);
// output is given as �1
sir my question is that while applying int output was the maximum value which was given n in the case of byte or short the output is �1.


In this case the result of the floating point division is the same (positive infinity), however to convert to a byte a two step process is used, first it is converted to an int as the first example was, then the int is converted to a byte. when the int is converted to a byte all but the lowest order bits of the new type (in this case the lowest 8) are discarded, so the remaining bits are all 1 which is -1.
hope that helps


------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
reply
    Bookmark Topic Watch Topic
  • New Topic