The following program declares an array with five values already initialized. The program then calculates the average
Question:
The following program declares an array with five values already initialized. The program then calculates the average of the values and outputs it to the screen.
Scanner keyedInput = new Scanner (System.in); double [ ] marks = {34.7, 54.1, 34.8, 99.6, 43.6, 43.2}; double total=0; double average; System.out.println("These are the marks:"); for (int i = 0; i<=5; i= i + 1) { System.out.println(marks[i]); } for (int i = 0; i<=5; i= i + 1) { total = total + marks[i]; } average = total/6; average = average * 10; average = Math.round(average); average = average/10; System.out.println("The average mark is:"); System.out.println(average);
Alter the program so that the following marks are added to the list: 65.8, 44.8, 88.6.
The program should then output a new,corrected average.
- Please make sure that arrays are used
- Make sure this code works with Java 12.5 I Use Java with Maven
- Thank you for your help
Numerical Methods With Chemical Engineering Applications
ISBN: 9781107135116
1st Edition
Authors: Kevin D. Dorfman, Prodromos Daoutidis