• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why the code is giving the answer as -1

 
Vinay Belagavi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can anyone explain me why the below code is giving the answer as
-1?
public class DoubleDemo
{
public static void main(String[] args)
{
double d1=1.0;
double d2=0.0;
byte b=1;
d1=d1/d2;
b=(byte)d1;
System.out.println(b);
}
}
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read my comments in the snippet below:

Here's the byte code of your program:
[ October 14, 2006: Message edited by: Barry Gaunt ]
 
Vinay Belagavi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Barry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic