Processing Input with Sentinel Values:
import java.util.Scanner;

public class InputRedirection
{
	public static void main(String [] args)
	{
	    int [] scores = new int[20];
            Scanner input = new Scanner(System.in);
            double total = 0;
            double average;
            int num = 0,i;
            boolean done = false;
	    String data;
	    System.out.println("Enter your scores followed by \"Q\":");
            while(!done)
            {
		data = input.next();
		if(data.equalsIgnoreCase("Q"))
		   done = true;
		else
		{
		 scores[num]= Integer.parseInt(data);
	         total += scores[num];
                 num++;
		}
             }
	    System.out.print("Your scores are ");
            for(i=0; i<num; i++)
            {
               if(i>0)
                 System.out.print(", ");
               System.out.print(scores[i]);
            }
             
             average = total / num;
             System.out.println("\ntotal = " + total + "\naverage = " + average);
	}
}

input.txt:

80
70
85
95
100
50
Q

Input / Output Redirection on a command line:

Partially Filled Arrays:
import java.util.Scanner;

public class InputRedirection
{
	public static void main(String [] args)
	{
	    int [] scores = new int[20];
            Scanner input = new Scanner(System.in);
            double total = 0;
            double average;
            int num = 0,i;
 	    System.out.println("Enter your scores:");
            while(input.hasNextInt())
            {
		if(num < 20)
		{
		 scores[num]= input.nextInt();
	         total += scores[num];
                 num++;
		}
             }
	    System.out.print("Your scores are ");
            for(i=0; i<num; i++)
            {
               if(i>0)
                 System.out.print(", ");
               System.out.print(scores[i]);
            }
             
             average = total / num;
             System.out.println("\ntotal = " + total + "\naverage = " + average);
	}
}