Skip to content

Instantly share code, notes, and snippets.

@imryan
Created October 8, 2013 16:38
Show Gist options
  • Select an option

  • Save imryan/6887518 to your computer and use it in GitHub Desktop.

Select an option

Save imryan/6887518 to your computer and use it in GitHub Desktop.
Calculates student average from 5 recent grades.
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;
}
}
@joeyv
Copy link
Copy Markdown

joeyv commented Oct 8, 2013

sucks, did it first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment