Answer to Question #289826 in Java | JSP | JSF for jeffy

Question #289826

Q1.Given an array int[] array={1,2,3,4,5}, write down the code to calculate the sum and average of the array.


1
Expert's answer
2022-01-22T12:59:25-0500


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		int[] array = { 1, 2, 3, 4, 5 };


		int sum = 0;


		for (int i = 0; i < array.length; i++) {
			sum += array[i];
		}
		double average = (double) sum / (double) array.length;
		System.out.println("Sum: " + sum);
		System.out.println("Average: " + average);


	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog