when i use following code i do not get correct output:
In this the function maxHeartRate returns an Integer value.Lets take it equal to 199.
public String targetHeartRate()
{
double a = maxHeartRate()/2;
double b = ((85/100)*(maxHeartRate()));
String c = a+"-"+b;
return c;
}
Using above code i get String c as :99.0-0.0
But when i change
double b = ((85/100)*(maxHeartRate()));
to
double b = ((85*maxHeartRate())/100);
i get the correct output.
Then String c becomes:99.0-169.0
My question is why i am not getting the correct output even though both should evaluate to the same value?
Also i am not able to post correctly in this forum, i put my code snippet in the code section then also it gives me error like:
The code snippet in your post is formatted incorrectly. Please use the Code button in the editor toolbar when posting whitespace-sensitive text.