Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Loops5
- {
- static double [] scores;
- static Scanner input = new Scanner(System.in);
- public static void main(String[] args)
- {
- System.out.println("How many scores to enter?");
- int sizeOFArray = input.nextInt();
- scores = new double[sizeOFArray];
- input();
- calcAverage();
- }
- public static void input()
- {
- for(int i=0; i < scores.length; i++)
- {
- System.out.println("Enter score");
- scores[i] = input.nextDouble();
- }
- System.out.println("All marks entered.");
- output();
- }
- public static void output()
- {
- for(int i=0; i < scores.length; i++)
- {
- System.out.println(scores[i]);
- }
- }
- public static void calcAverage()
- {
- double total =0;
- for(int i =0; i< scores.length; i++)
- {
- total = total + scores[i];
- }
- double average = total/scores.length;
- System.out.println("The average is " + average);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement