import java.util.*;
class FirstClass{
public static float printAvg(int a, int b, int c) {
float avg = (a+b+c)/3;
return avg;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(print);
}
}
I started learning java a week ago and i was given a question to make a function that finds the average of 3 given numbers and i wrote the above code.
I am getting correct outputs for the integer outputs like for 1,2,3 avg = 2 which got printed correctly but if the avg is a float value like 4.2 it is printed as 4.0. I tried to take output in another value as a float and then print it but it is not working. What should I do to fix this?
New contributor
Mohd. Saad Haider is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.