# Thread: help w/ storing/scanning numbers in arrays(what am i doing wrong)

1. Member
Join Date
Oct 2010
Posts
44
Rep Power
0

## help w/ storing/scanning numbers in arrays(what am i doing wrong)

hey guys need some help w/ storing scanning numbers in arrarys

here are my instructions, code, and output

A Computer Technology Instructor has a small class of 10 students. The instructor evaluates the performance of students in the class by administering 2 midterm tests and a Final Exam.

Write a program that prompts the instructor to enter the 10 grades of midterm 1 and store these numbers in an array. Next prompt for the 10 grades of midterm 2 and store these numbers in a different array. Next prompt for the 10 grades of the Final Exam and store these in a different array. Next add midterm1 to midterm2 to Final and store the totals in a different array. Next, scan the array that has the totals and identify the minimum grade and maximum grade. Inform the instructor of the minimum grade and maximum grade.

Java Code:
```
import java.util.Scanner;
import java.util.Arrays;

public class Arrays
{   public static void main(String[] args)
{
//input scanner
Scanner input = new Scanner(System.in);

double[]midTerm1= new double [10];
for (int A = 0; A <midTerm1.length; A++){
midTerm1[A] = input.nextDouble();
}
System.out.println("Now");

double[]midTerm2=new double[10];
for(int B=0; B<midTerm2.length;B++){
midTerm2[B] = input.nextDouble();
}
System.out.println("Now");

//Prompt User for Final Exam grades
double[]finalExam = new double[10];
for(int C = 0; C<finalExam.length; C++){
finalExam[C] = input.nextDouble();
}
int [] grades = new int [10];

double max = 0;
double min = 0;

//Display highest score
for (int t = 0; t < grades.length; t ++)
{
}

//Display lowest score
{
}

}

System.out.print("Your highest test score is: " + max);
System.out.print("Your lowest test score is: " + min);
System.out.print("You have entered following grades for midTerm1:    ");
System.out.println(Arrays.toString(midTerm1));
System.out.print("You have entered following grades for midTerm2:    ");
System.out.println(Arrays.toString(midTerm2));
System.out.print("You have entered following grades for Final Exam:   ");
System.out.println(Arrays.toString(finalExam));

}
}```
output(using eclipse btw)

Your highest test score is: 0.0Your lowest test score is: 0.0You have entered following grades for midTerm1: [1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 5.0, 67.0, 7.0, 5.0]
You have entered following grades for midTerm2: [5.0, 5.0, 7.0, 6.0, 54.0, 53.0, 3.0, 5.0, 4.0, 4.0]
You have entered following grades for Final Exam: [3.0, 4.0, 5.0, 6.0, 5.0, 47.0, 7.0, 7.0, 5.0, 4.0]

2. Senior Member
Join Date
Jan 2011
Location
Bangalore, India
Posts
102
Rep Power
0
as far as I see grades is only initialized... Nothing else is done on it.
Java Code:
`int [] grades = new int [10];`
All the 10 values will be zero.
Next you are running a for loop to find the max. It'll definitely be zero.

3. Member
Join Date
Oct 2010
Posts
44
Rep Power
0
here is my updated code and output...i believe im heading in the right direction but i dont think it is calculating my min and max grade correctly

Java Code:
```import java.util.Scanner;
import java.util.Arrays;

public class Arrays
{ public static void main(String[] args)
{
//input scanner
Scanner input = new Scanner(System.in);

double[]midTerm1= new double [10];
for (int A = 0; A <midTerm1.length; A++){
midTerm1[A] = input.nextDouble();
}
System.out.println("Now");

double[]midTerm2=new double[10];
for(int B=0; B<midTerm2.length;B++){
midTerm2[B] = input.nextDouble();
}
System.out.println("Now");

//Prompt User for Final Exam grades
double[]finalExam = new double[10];
for(int C = 0; C<finalExam.length; C++){
finalExam[C] = input.nextDouble();
}
double [] grades = new double [10];

for (int i = 0; i < grades.length;i ++){
}

double max = 0;
double min = 0;

for (int i=1; i<grades.length; i++) {
}
}

for (int i=1; i<grades.length; i++) {
}
}

System.out.print("Your highest test score is: " + max);
System.out.print("Your lowest test score is: " + min);
System.out.print("You have entered following grades for midTerm1:    ");
System.out.println(Arrays.toString(midTerm1));
System.out.print("You have entered following grades for midTerm2:    ");
System.out.println(Arrays.toString(midTerm2));
System.out.print("You have entered following grades for Final Exam:   ");
System.out.println(Arrays.toString(finalExam));

}
}```
and here is my output after entering the grades

Your highest test score is: 281.0Your lowest test score is: 198.0You have entered following grades for midTerm1: [89.0, 98.0, 78.0, 87.0, 56.0, 65.0, 45.0, 54.0, 88.0, 99.0]
You have entered following grades for midTerm2: [100.0, 78.0, 87.0, 98.0, 67.0, 87.0, 88.0, 99.0, 92.0, 94.0]
You have entered following grades for Final Exam: [90.0, 90.0, 88.0, 34.0, 75.0, 100.0, 99.0, 88.0, 77.0, 88.0]

4. Member
Join Date
Oct 2010
Posts
44
Rep Power
0
can anyone confirm if i am right or not?

5. Senior Member
Join Date
Jan 2011
Location
Bangalore, India
Posts
102
Rep Power
0
everything looks fine according to me, except max score and min score.
What are they supposed to be? is it the max/min of all the terms or max/min of the total of all terms(grade). The second case is what you are getting now.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•