Results 1 to 5 of 5
Thread: Exception Handling
- 02-19-2011, 06:44 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 93
- Rep Power
- 0
Exception Handling
This is probably a dumb question but,
why does
not give an exception, but the following code does:Java Code:int numerator = read.nextInt();//input = 20 int denominator = read.nextInt();//input = 4 int fraction = numerator/denominator; System.out.printf("Fraction: %d",fraction);
Java Code:int numerator = read.nextInt();//input = 20 int denominator = read.nextInt();//input = 4 double fraction = (double) numerator/denominator; System.out.printf("Fraction: %d",fraction);
- 02-19-2011, 07:00 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,589
- Blog Entries
- 7
- Rep Power
- 17
- 02-19-2011, 11:52 PM #3
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
%d is the placeholder for an int type, fraction is a double in your second example so you need to use %f
- 02-19-2011, 11:56 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,560
- Rep Power
- 11
Jos++
In fact this one is so common (I mean "double" starts with a 'd'...) that Sun's JVM message uncharacteristically tells you what you should have written...
- 02-20-2011, 12:00 AM #5
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Similar Threads
-
Exception Handling
By liljester in forum New To JavaReplies: 4Last Post: 06-21-2010, 03:09 PM -
Exception Handling help
By MZA in forum New To JavaReplies: 3Last Post: 02-10-2010, 09:23 AM -
JAXP exception handling
By jovenky in forum Advanced JavaReplies: 0Last Post: 05-27-2008, 01:37 PM -
Exception Handling...
By focus_nitin in forum New To JavaReplies: 1Last Post: 02-16-2008, 03:13 AM -
JDBC - Exception handling
By Java Tip in forum Java TipReplies: 0Last Post: 12-05-2007, 04:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks