Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

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