This Java program prompts the user to input the limit of an array, then takes input values from the user and calculates the sum and average of the array values. Here's a brief explanation of what the program does:
import java.util.Scanner; class Average { public static void main(String[] args) { Scanner input =new Scanner(System.in); System.out.print("Enter the Array Limit :"); int l =input.nextInt(); int [] a =new int[l]; int sum = 0; for(int i=0;i<l;i++) { System.out.printf("Element of a[%d] :",i); a[i]=input.nextInt(); } for(int i=0; i < l ; i++) sum = sum + a[i]; double ave = sum / l; System.out.println("Sum of Array Value : " + sum); System.out.println("Average of Array Value : " + ave); } }
Enter the Array Limit :5 Element of a[0] :1 Element of a[1] :20 Element of a[2] :30 Element of a[3] :45 Element of a[4] :67 Sum of Array Value : 163 Average of Array Value : 32.0
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions