public class ArgumentDemo
1:
2: import java.util.Scanner;
3:
4: /**
5: A demonstration of using indexed variables as arguments.
6: */
7: public class ArgumentDemo
8: {
9: public static void main(String[] args)
10: {
11: Scanner keyboard = new Scanner(System.in);
12: System.out.println("Enter your score on exam 1:");
13: int firstScore = keyboard.nextInt( );
14: int[] nextScore = new int[3];
15:
16: for (int i = 0; i < nextScore.length; i++)
17: nextScore[i] = firstScore + 5 * i;
18:
19: for (int i = 0; i < nextScore.length; i++)
20: {
21: double possibleAverage = getAverage(firstScore, nextScore[i]);
22: System.out.println("If your score on exam 2 is " +
23: nextScore[i]);
24: System.out.println("your average will be " +
25: possibleAverage);
26: }
27: }
28:
29: public static double getAverage(int n1, int n2)
30: {
31: return (n1 + n2) / 2.0;
32: }
33: }
34:
35:
36:
37:
38:
39:
40: