Results 1 to 4 of 4
Thread: number checker?
- 03-05-2011, 04:53 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
number checker?
I'm building a small cmd line java app that asks you for a distance to get to one place, and then how much time you want to get there. The program will then generate the speed needed to get there in that time. The program will also tell you if you must exceed 65 mph, and it will add five minutes to the time for every 100 miles you input. Say that you input 250 for the distance, the program should know that there is a total of ten minutes of rest stops. Now, I've written all of that except for the five minute rest stop part. How would I get the program to know that if I set the distance to 560, that per each 100 there is five minutes added to the time variable. So, there would be 25 minutes total in rest stops.
- 03-05-2011, 05:11 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Use the division operator.
Java Code:public class DvisionEg { public static void main(String[] args) { System.out.println("560/100 is " + 560 / 100); } }
- 03-05-2011, 05:27 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 8
- Rep Power
- 0
that doesn't help; I'm not using Ints so that would return an odd decimal number. Also, even if i were doing Ints, if i were to do 500 /5 i would get 100, which i still wouldn't know what to do with. I need the program to know how many hundreds there are (e.g. there are five hundreds in 500) and then add five minutes to the time variable for each 100
-
His suggestion helps me and works for me. I'd simply cast my doubles to ints and divide by 100 using int division as pbrockway suggests above.
Similar Threads
-
isbn checker
By jingliu316 in forum New To JavaReplies: 2Last Post: 10-27-2010, 07:31 PM -
Spell Checker in Swing
By dhaivat in forum New To JavaReplies: 2Last Post: 07-01-2010, 05:08 PM -
Printing the Number of Times a Number in a Range Shows up
By space4rent00 in forum New To JavaReplies: 1Last Post: 02-05-2010, 10:42 PM -
Grammar Checker
By zaz_rin in forum New To JavaReplies: 1Last Post: 07-19-2009, 02:01 PM -
ISBN Checker
By blobs86 in forum New To JavaReplies: 1Last Post: 03-23-2009, 11:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks