aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why the  code is giving the answer as -1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why the  code is giving the answer as -1" Watch "why the  code is giving the answer as -1" New topic
Author

why the code is giving the answer as -1

Vinay Belagavi
Greenhorn

Joined: Jun 15, 2006
Posts: 29
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

Joined: Aug 03, 2002
Posts: 7729
Read my comments in the snippet below:

Here's the byte code of your program:
[ October 14, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Vinay Belagavi
Greenhorn

Joined: Jun 15, 2006
Posts: 29
Thanks for the reply Barry.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why the code is giving the answer as -1
 
Similar Threads
SJCP
ques
Casting!!!!!!!!
Mock question from Jaworski
A mock question