Age average | Sololearn: Learn to code for FREE!

0

Age average

Why I can’t get correct result , 28.4? public class Program { public static void main(String[] args) { int grace = 10; int edward = 21; int rose = 15; int mom = 46; int dad = 50; float average = (grace+edward+rose+mom+dad)/5; System.out.println(average); } }

10/25/2019 12:11:35 AM

Mali

3 Answers

New Answer

+1

You defined the numbers as integers, so when they are divided, they are divided as integers, rounding the decimal to whole number. If you want to keep the decimal, try: //my code is in C#, adapt it to Java using System; public class Program { public static void Main(String[] args) { float grace = 10; float edward = 21; float rose = 15; float mom = 46; float dad = 50; float average = (grace+edward+rose+mom+dad)/5; Console.WriteLine(average); } }

+1

What does this output?

0

24.0