Advertisement
We've partnered up with Nixers.com to offer a space where you can talk directly to Peter from Nixers.com and get an exclusive Boards.ie discount code for a free job listing. If you are recruiting or know anyone else who is please check out the forum here.
If you have a new account but can't post, please email Niamh on [email protected] for help to verify your email address. Thanks :)

Basic Java Program Help (Target-Heart-Rate Calculator)

2»

Comments

  • Registered Users Posts: 476 ✭✭ RoRo979


    i changed %f to %d but i am still getting an error,
    Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier 'd'
    	at java.util.Formatter.format(Unknown Source)
    	at java.io.PrintStream.format(Unknown Source)
    	at java.io.PrintStream.printf(Unknown Source)
    


  • Registered Users Posts: 3,532 Unregistered.


    RoRo979 wrote: »
    i changed %f to %d but i am still getting an error,
    Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier 'd'
        at java.util.Formatter.format(Unknown Source)
        at java.io.PrintStream.format(Unknown Source)
        at java.io.PrintStream.printf(Unknown Source)
    

    Ok, stop using printf until you have verified that the original problem is solved. Just use println. You can go back to printf later if you want, but you asked for help with the logic on your code, this goes beyond that.


  • Registered Users Posts: 476 ✭✭ RoRo979


    really from where i started off I am now a few steps back haha :) originally i was looking for a precise target heart rate as i was only getting 170 instead of 173 with a double.


  • Registered Users Posts: 476 ✭✭ RoRo979


    hahaha oh how java is challenging :) right so i fixed that error and i have just discovered that i am back to where i was at the start just with different code. i am looking for the target heart range to be precise.


  • Registered Users Posts: 3,532 Unregistered.


    RoRo979 wrote: »
    hahaha oh how java is challenging :) right so i fixed that error and i have just discovered that i am back to where i was at the start just with different code. i am looking for the target heart range to be precise.

    Did you not read about casting as was mentioned earlier?


    This is the soution:
    int result = (int) (( (double) 204/100) *85) ;


    Breakdown:


    ((double) 204/100) // result of the division will be a double, eg 2.04


    (int) ( (double) 204/100) *85) // the result of everything in the brackets will be an int.

    So even though 2.04 * 85 = 173.4 inside the brackets, casting means that this is transformed to an integer, which is 173.


  • Advertisement
  • Registered Users Posts: 476 ✭✭ RoRo979


    ahhhh it works now hahaha, i did read it and i tried it but an error came up every time, yessss, thank you soo much. I am exremely grateful for all the help you all gave me :):):)


Advertisement