Created
October 8, 2013 16:38
-
-
Save imryan/6887518 to your computer and use it in GitHub Desktop.
Calculates student average from 5 recent grades.
This file contains 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) { | |
// Declare variables | |
Scanner sc = new Scanner(System.in); | |
int grade1 = 0; | |
int grade2 = 0; | |
int grade3 = 0; | |
int grade4 = 0; | |
int grade5 = 0; | |
// Get user input | |
grade1 = sc.nextInt(); | |
grade2 = sc.nextInt(); | |
grade3 = sc.nextInt(); | |
grade4 = sc.nextInt(); | |
grade5 = sc.nextInt(); | |
// Output average | |
System.out.println("\nAverage: " + getAverage(grade1, grade2, grade3, grade4, grade5)); | |
} | |
public static int getAverage(int g1, int g2, int g3, int g4, int g5) | |
{ | |
// Calculate the average & return the value | |
int average = (g1 + g2 + g3 + g4 + g5) / 5; | |
return average; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sucks, did it first