0% found this document useful (0 votes)
11 views1 page

Array

This Java code defines a main method that uses a Scanner to input the length of a student grades array, loops through the array to sum the grades and calculate the average, and prints the average.

Uploaded by

Fear
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Array

This Java code defines a main method that uses a Scanner to input the length of a student grades array, loops through the array to sum the grades and calculate the average, and prints the average.

Uploaded by

Fear
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class array {

public static void main(String[] args) {

Scanner read = new Scanner(System.in);

int numEntry;

int total=0;

int[] grades={87,90,77,89,88,94,95,83,82,75,};

float average = 0;

System.out.print("Enter array length: ");

numEntry=read.nextInt();

if (numEntry>grades.length) {

System.out.println("Invalid entry!!");

}else {

for(int i=0; i<=numEntry-1; i++) {

System.out.println("Grade " +grades[i]);

total=total+grades[i];

average = total/numEntry;

System.out.println("The average is: "+ average);

You might also like