Created
July 8, 2014 14:37
-
-
Save SlayterDev/5f2ea50d1e0514a1880b to your computer and use it in GitHub Desktop.
Calculate the average of a number of grades
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class Average { | |
| public static void main(String[] args) { | |
| // TODO Auto-generated method stub | |
| Scanner input = new Scanner(System.in); | |
| System.out.println("Brad's grade averager!!"); | |
| System.out.println("========================================"); | |
| System.out.println("Enter the number of grades to average: "); | |
| int numGrades = input.nextInt(); | |
| // create array to hold grades | |
| int[] grades = new int[numGrades]; | |
| // Fill the array from the console | |
| for (int i = 0; i < numGrades; i++) { | |
| System.out.println("Enter grade " + (i+1) + ": "); | |
| grades[i] = input.nextInt(); | |
| } | |
| // Calculate average | |
| int sum = 0, average; | |
| for (int i = 0; i < numGrades; i++) { | |
| sum += grades[i]; | |
| } | |
| average = sum / numGrades; | |
| System.out.println("Your average is: " + average); | |
| input.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment