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); } }
3 Answers
+ 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
Hot today
sizeof funtion with a loop in c!
1 Votes