I need help about Average calculator....
Q: Given that you have five input values and “average” method, calculate the average value for the five input values inside the average method and return it .
public class MyCalculator {
int input1 = 10;
int input2 = 20;
int input3 = 30;
int input4 = 40;
int input5 = 50;
public float average() {
// TODO: write java code to calculate the average for all input variables
return 0;
}
}
The method could look like this:
public float average(int input1, int input2, int input3, int input4, int input5) {
return (input1 + input2 + input3 + input4 + input5 ) / 5;
}
Then all you need to do is call average with the five parameters passed to it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.