Sunday, 15 August 2010

math - Java average calculation -



math - Java average calculation -

when run next code in java not give me right average result who's supposed 97.5. can help me please.

//class public class numerictypes { public static void main (string [] args) { final int number = 2 ; // number of scores final int score1 = 100; // first test score final int score2 = 95; // sec test score final int boiling_in_f = 212; // freezing temperature int ftoc; // temperature in celsius double average; // arithmetic average string output; // line of output print out // find arithmetic average average = (score1 + score2) / number; output = score1 + " , " + score2 + " have average of " + average; system.out.println(output); // convert fahrenheit temperatures celsius ftoc = (boiling_in_f - 32) * 5/9; output = boiling_in_f + " in fahrenheit " + ftoc + " in celsius."; system.out.println(output); system.out.println(); // leave blank line } }

you performing integer math, cast 1 of values double , you'll right result.

average = ((double)(score1 + score2)) / number;

java math

No comments:

Post a Comment