Results 1 to 5 of 5
Thread: Why isnt this working?
- 04-02-2010, 07:57 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 2
- Rep Power
- 0
-
Please define "not working?"
One issue, which I'm not sure is a problem: You're doing int division. 1/2 will result in 0. 1.0/2 will result in 0.5.
Try changing 2112 to 2112.0. Also, you should use parenthesis -- when do you want the mod operator to act?
- 04-02-2010, 11:44 PM #3
Try changing 'int' to 'double'.
-
- 04-03-2010, 02:36 AM #5
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
Hi, this refers to type casting. You can cast type int to double, but reverse not, because it will lose precision. In some IDE, it will give 'Type mismatch: cannot convert from double to int' tip. If you must cast double to int, you can use the following form:
Now, it will be 22, but not 23 and any others.Java Code:int i = (int) 22.99;
So, you can change your formula to:
and the result is 9.Java Code:int foo = (int) 10.9 + 2112 / 100 % 2 - 2;
For details, you can refer some java beginners books.
Similar Threads
-
How can i use keyevent even tho the program isnt selected?
By Addez in forum New To JavaReplies: 11Last Post: 12-25-2009, 10:30 PM -
My rotate 2d pos method isnt working correctly..
By Addez in forum New To JavaReplies: 5Last Post: 12-01-2009, 09:04 AM -
The code isnt working unless I add print statements at diffrent points!:confused:
By Addez in forum New To JavaReplies: 6Last Post: 11-12-2009, 10:50 AM -
why isnt my background color displaying correctly ?
By nicnicnic in forum Java 2DReplies: 8Last Post: 10-29-2009, 10:54 AM -
why isnt it sending value
By snitdesne in forum New To JavaReplies: 5Last Post: 10-24-2008, 07:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks