Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: help w/ storing/scanning numbers in two dimensional arrays

1. ## help w/ storing/scanning numbers in two dimensional arrays

have a assignment that we have to accomplish the same work as in a previous assignment except use two dimensional arrays... this is my previous assignment

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 Midterm2 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 total of grades 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.

Note : do not assume that the grades are in the range 0 to 100. Your program should function properly whether the grades are in the range 0 to 100 or any other range.

*****and this is my next assignments instructions

Use one two-dimensional array to accomplish the same work you did in the last Assignment. Think of the students as being the columns of the two-dimensional array. Think of the scores of Midterm 1 as occupying the first row, scores of Midterm 2 occupying the next row, scores of the Final Exam occupying the next row. The total of the 3 exams occupying the next row. Inform the instructor of the minimum total grade and the maximum total grade.

***and here is my code, got errors all over the place and not sure where to begin or iif im even in the ballpark

```
import java.util.Scanner;
import java.io.*;

public class Assign10_Roberts{
public static void main(String[] args){

//input Scanner
Scanner input=new Scanner(System.in);

int midTerm1=0;

int midTerm2=0;

int finalExam=0;

System.out.println("Enter the 10 Midterm 1 grades: ");
for (int i = 0; i < grades.length; i++){

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

}

System.out.print("Enter the 10 Midterm 2 grades: ");

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

for (int j = 0; j < grades.length; j++)

}

System.out.print("Enter the 10 Final Exam grades: ");

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

for (int j = 0; j < grades.length; j++)

}

for (int i=0;i<10;i++)

for (int i=1;i<10;i++)

{

}

}
}
}```

also this is cross posted, thanks
help w/ storing/scanning numbers in two dimensional arrays - Java Forums

2. ## Re: help w/ storing/scanning numbers in two dimensional arrays

Define "get errors all over the place"...compile time errors? Runtime errors? Post them all in full, which will help the diagnosis.

3. ## Re: help w/ storing/scanning numbers in two dimensional arrays

heres the errors im getting

```
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Duplicate local variable i
j cannot be resolved to a variable
Duplicate local variable i
j cannot be resolved to a variable
Duplicate local variable i
midterm1 cannot be resolved to a variable
midterm2 cannot be resolved to a variable
Syntax error, insert ";" to complete Statement
Type mismatch: cannot convert from int[] to int
Type mismatch: cannot convert from int[] to int
Duplicate local variable i
The operator > is undefined for the argument type(s) int, int[]
Type mismatch: cannot convert from int[] to int
The operator < is undefined for the argument type(s) int, int[]
Type mismatch: cannot convert from int[] to int

at Assign10_Roberts.main(Assign10_Roberts.java:39)
```

4. ## Re: help w/ storing/scanning numbers in two dimensional arrays

There really are all sorts of errors!

For a start, there are multiple for loops inside each other which is causing issues with duplicate variables.

I would fix these first.

5. ## Re: help w/ storing/scanning numbers in two dimensional arrays

ok here is my updated code and errors

```
import java.util.Scanner;
import java.io.*;

public class Assign10_Roberts{
public static void main(String[] args){

//input Scanner
Scanner input=new Scanner(System.in);

int midTerm1=0;

int midTerm2=0;

int finalExam=0;

for(int i=0; i<10; i++) {
// Midterm 1
}
for(int i=0; i<10; i++) {
// Midterm 2
}
for(int i=0; i<10; i++) {
// Final Exam

System.out.println("Enter the 10 Midterm 1 grades: ");

System.out.print("Enter the 10 Midterm 2 grades: ");

System.out.print("Enter the 10 Final Exam grades: ");
}

{

}

}

}```
minGrade cannot be resolved to a variable
maxGrade cannot be resolved to a variable

at Assign10_Roberts.main(Assign10_Roberts.java:39)

6. ## Re: help w/ storing/scanning numbers in two dimensional arrays

Nowhere is min/maxgrade defined. They need to be defined to be used. For example
```int mingrade = 0;
//now you can use the variables.```
Typically, since you are looking at min/max values, you want to initialize these values to their opposite extremes, for example initialize mingrade to Integer.MAX_VALUE and vice-versa for maxgrade.

7. ## Re: help w/ storing/scanning numbers in two dimensional arrays

It also seems that you are trying to access grades[i] outside the scope of the for loop. So I will be undefined as well. Since it is a 2 dimensional array and you only need 3 grades and a total, for 10 students. The array should not be [10][10] but [4][10] which means you have 4 rows and 10 columns.

If you are still having trouble, let us know.

Dejan

8. ## Re: help w/ storing/scanning numbers in two dimensional arrays

here is my updated code and errors

```public class Assign10_Roberts{
public static void main(String[] args){

//input Scanner
Scanner input=new Scanner(System.in);

int midTerm1=0;
int midTerm2=0;
int finalExam=0;

for(int i=0, j=0; i<10; i++) {
// Midterm 1
}
for(int i=0; i<10; i++) {
// Midterm 2
}
for(int i=0, j=0; i<10; i++) {
// Final Exam

System.out.println("Enter the 10 Midterm 1 grades: ");

System.out.print("Enter the 10 Midterm 2 grades: ");

System.out.print("Enter the 10 Final Exam grades: ");

}

}

}```

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The operator > is undefined for the argument type(s) int, int[]
Type mismatch: cannot convert from int[] to int
The operator < is undefined for the argument type(s) int, int[]
Type mismatch: cannot convert from int[] to int

at Assign10_Roberts.main(Assign10_Roberts.java:49)

9. ## Re: help w/ storing/scanning numbers in two dimensional arrays

You cannot compare an int with an array...since your grades is a 2d array, you need to specify another index
mingrade < grades[i][0] or something to that effect. Also, re-read my post above, because this code will most likely always produce a mingrade of 0.

10. ## Re: help w/ storing/scanning numbers in two dimensional arrays

not sure is this is any better here is what i changed

```import java.util.Scanner;
import java.io.*;

public class Assign10_Roberts{
public static void main(String[] args){

//input Scanner
Scanner input=new Scanner(System.in);

int midTerm1=0;
int midTerm2=0;
int finalExam=0;

for(int i=0, j=0; i<10; i++) {
// Midterm 1
}
for(int i=0; i<10; i++) {
// Midterm 2
}
for(int i=0, j=0; i<10; i++) {
// Final Exam

System.out.println("Enter the 10 Midterm 1 grades: ");

System.out.print("Enter the 10 Midterm 2 grades: ");

System.out.print("Enter the 10 Final Exam grades: ");
{

public static double getCurrentMin (double [][] input) {
for (int row = 0; row < input.length; row++){
for (int column = 0; column < input [row].length; column++){
}
}

public static double getCurrentMax (double [][] input){
for (int row = 0; row < input.length; row++){
for (int column = 0; column < input [row].length; column++){

}

}

}

}

}```

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error, insert "}" to complete Block
Syntax error, insert "}" to complete Block
Syntax error, insert "}" to complete MethodBody

at Assign10_Roberts.main(Assign10_Roberts.java:44)

11. ## Re: help w/ storing/scanning numbers in two dimensional arrays

Format your code using tabs. This will make it a lot easier for you to tell where you have missing (or misplaced) closing braces.

The general convention is for each new block (anything surrounded by curly braces) should be indented, and the closing brace should be un-indented on a newline.

For example, here's your code with the tabs inserted (I've also put comments in on where the problems with braces are)

```import java.util.Scanner;
import java.io.*;

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

int midTerm1=0;
int midTerm2=0;
int finalExam=0;

for(int i=0, j=0; i<10; i++) {
// Midterm 1
}
for(int i=0; i<10; i++) {
// Midterm 2
}
for(int i=0, j=0; i<10; i++) {
// Final Exam

System.out.println("Enter the 10 Midterm 1 grades: ");

System.out.print("Enter the 10 Midterm 2 grades: ");

System.out.print("Enter the 10 Final Exam grades: ");
{
// missing curly braces here
// did you forget to finish your main method?

public static double getCurrentMin (double [][] input) {
for (int row = 0; row < input.length; row++){
for (int column = 0; column < input [row].length; column++){
}
}
// missing curly braces here

public static double getCurrentMax (double [][] input){