in order to add 3 arrays into one new array
first they must have the same dimension.
and the resulting array will be
result[k]=a[k]+b[k]+c[k] <--for all elements k=0...length
Code:
import java.util.Scanner;
import java.util.Arrays;
public class Assign9_Cheshire
{
public static void main(String[] args)
{
//Variable Declarations
Scanner input = new Scanner(System.in);
int averageScore;
int userInput;
int [] grades = new int [10];//define it first of all
//User Prompts midterm1
int[]midTerm1= new int [10];
for (int i = 0; i <midTerm1.length; i++){
System.out.println("Please enter a MidTerm1 grade: ");
midTerm1[i] = input.nextInt();
grades[i]=midTerm1[i];//you add the first results!!!
}
System.out.println("Thank you next");
//User prompt midterm2
int[]midTerm2=new int[10];
for(int j=0; j<midTerm2.length;j++){
System.out.println("Please enter a MidTerm2 grade: ");
midTerm2[j] = input.nextInt();
grades[j]+=midTerm2[j];//you add the second results!!!
}
System.out.println("Thank you next");
//User prompt final exam
int[]finalExam = new int[10];
for(int k = 0; k<finalExam.length; k++){
System.out.println("Please enter a Final Exam grade: ");
finalExam[k] = input.nextInt();
grades[k]+=finalExam[k];//last one to add!!!
}
int max = 0;
//To display highest score
for (int t = 0; t < grades.length; t ++)
{
if (grades[t] > max)
{
max = grades[t];
}
System.out.print("\nYour highest test score is: " + max);
//To display lowest score
int min = 100;
if(grades[t] < min)
{
min = grades[t];
}
}
System.out.print("\nYour lowest test score is: " + min);
System.out.print("You have entered for midTerm1: ");
System.out.println(Arrays.toString(midTerm1));
System.out.print("You have entered for midTerm2: ");
System.out.println(Arrays.toString(midTerm2));
System.out.print("You have entered for Final Exam: ");
System.out.println(Arrays.toString(finalExam));
}
}