0
Hello there! Why this is not working?
public class Program { public static void main(String[] args) { double[] revenue = {88750, 125430, 99700, 14500, 158000, 65000, 99000, 189000, 210000, 42000, 165800, 258900}; double sum = 0.0; for (int i = 0; i < revenue.length; i++) { sum = sum + revenue[i]; } System.out.println(sum); double average = sum / revenue.length; // Calculate the average using double arithmetic // Use printf to output the average with exactly two decimal places System.out.println(average); } } It is a bug or smth? why i cant pass this problem? the code works really fine, what should i do?
2 ответов
0
Florin Nisioi
What is the error you are facing?
0
For the exact reason why your code is not passing the tests, you need to provide the error, but based on instruction comments in your code, the final line wants you to print double number with exact 2 decimals, so for example if your number is 2.345678, your program needs to print 2.34 and this can be done with printf function. So replace this line in your code ->
System.out.println(average);
With this line ->
System.out.printf("%.2f", average);
If you still have errors, you need to provide them here for someone to can help.