18.1k views
3 votes
write a java method called printavg that takes in two floating point numbers and prints out the average of them.

1 Answer

5 votes

Answer:

public class Main {

public static void printAvg(float a, float b) {

float avg = (a + b) / 2;

System.out.println("The average between " + a + " and " + b + " is: " + avg);

}

public static void main(String[] args) {

printAvg(10.5f, 20.6f); //these numbers are just examples.

}

}

Step-by-step explanation:

you can use double instead of float, that way you don't have to put the 'f' next to the values