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

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

## 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

Java Code:
```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
http://www.javaprogrammingforums.com...html#post22064
Last edited by clemsontigers; 12-01-2010 at 02:32 AM.  Reply With Quote

2. ## What are the full error message contents?  Reply With Quote

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

## everything underlined as well as some of the i's and j's
Java Code:
```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++)

[/U]
for (int i=1;i<10;i++)

{

}```  Reply With Quote

4. ## No. The actual error messages.

Something like this, if it's a runtime error:
Java Code:
```java.lang.NumberFormatException: For input string: "c"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.lang.Integer.parseInt(Integer.java:499)
at base.base.<init>(base.java:17)```

Or something like this if it's compile-time:
Java Code:
`(line 20, base.java) missing method body, or declare abstract`  Reply With Quote

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

## oh oops...heres the error im gettin

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)  Reply With Quote

6. Senior Member Join Date
Apr 2010
Location
Philippines
Posts
580
Rep Power
10

## Notice the bold for loop, I tink you forgot to put opening ang closing braces ("{}").
Java Code:
```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++)

}
[b]
for (int i=0;i<10;i++)

[/b]
for (int i=1;i<10;i++)

{

}```  Reply With Quote

7. Senior Member Join Date
Apr 2010
Location
Philippines
Posts
580
Rep Power
10

## I have something that I want you to see.

Both dimension are declared 10.

in 2d array, the first array is the ROW and the second array is column
Java Code:
`int[][]grades= new int[this is ROW][this is column];`
Your teacher told you to have
• Midterm1 as first row
• Midterm2 as next row
• FinalExam as next row
• Total of three(3) exams as next row  Reply With Quote

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

## ok here is my updated code

Java Code:
```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: ");
}

{

}

}

}```
and this is the error im getting  Reply With Quote

9. Senior Member Join Date
Apr 2010
Location
Philippines
Posts
580
Rep Power
10

## and what error do you get?  Reply With Quote

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

## sorry i thought it pasted along w/ the rest...here is my errors

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

at Assign10_Roberts.main(Assign10_Roberts.java:39  Reply With Quote

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

## here is my updated code and errors

Java Code:
```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)  Reply With Quote

12. Senior Member Join Date
Apr 2010
Location
Philippines
Posts
580
Rep Power
10

## Java Code:
```  Reply With Quote

13. Senior Member Join Date
Apr 2010
Location
Philippines
Posts
580
Rep Power
10

## You declare grades as 2D array.
Java Code:
`int[][]grades= new int;`
Threfore, when getting or setting value to grades you ALWAYS need to put the arrays.
Java Code:
` grades[array/row][array/column]`
See the code in bold letters Originally Posted by clemsontigers here is my updated code and errors

Java Code:
```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: ");

}

}

}```
Last edited by mine0926; 12-02-2010 at 02:21 AM.  Reply With Quote

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

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

Java Code:
```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)  Reply With Quote

15. Senior Member Join Date
Apr 2010
Location
Philippines
Posts
580
Rep Power
10

## I would suggest that you start from scratch and follow what your teacher and members of both forums instructed/suggested you.
Also, use proper indention to properly and easily debug opening and closing braces.

The code you are showing has lots of error (compile, runtime and logical error) and far from the intruction gave to you.

Please dont get me wrong, and dont think that you will not be able to do this. I was just thinking that it will be easier for you
to understand these if you start from scratch and we are willing to help you here.  Reply With Quote

16. Senior Member Join Date
Apr 2010
Location
Philippines
Posts
580
Rep Power
10

## Here is your code if proper indention is used.
Java Code:
```import java.util.Scanner;
import java.io.*;

public class TrialONLY{
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: ");
{   //<--------- What this doing?
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++)
{
{
}
}
}
}
}```  Reply With Quote

#### Posting Permissions

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