# Thread: Help with Two Dimensional Array

1. Member Join Date
Dec 2010
Posts
18
Rep Power
0

## Help with Two Dimensional Array

Okay so I have a two dimensional array and I am trying to find out how many even numbers have been generated, and I need to display the count. Below I started trying to create a method for findEven but ran into some problems with it when I tried to compile. Im not sure if I wrote the method correctly. Any help would greatly be appreciated.

Java Code:
```import java.util.*;
import java.math.*;

public class twodim {

public static void (findEven)
for (x = 2;  x<= 20; x = x + 2) {
System.out.println( x );
}

for (y = 2;  y<= 20; y = y + 2) {
System.out.println( y );
}

public static void main(String[] args) {

final int row = 4;
final int col = 4;

Random rand = new Random();

int [][] twoDarray = new int [row][col];

for (int x = 0; x < twoDarray.length; x++) {

for (int y = 0; y < twoDarray[x].length; y++) {

twoDarray[x][y] = rand.nextInt(1000);
}
}

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

for(int j = 0; j < twoDarray[i].length; j++) {

System.out.print(twoDarray[i][j] + " ");

}
System.out.println();
}

}
}```  Reply With Quote

2. Senior Member  Join Date
Oct 2010
Location
Germany
Posts
785
Rep Power
12

## Oohhhh ...
public static void (findEven)
for (x = 2; x<= 20; x = x + 2) {

this is not a java syntax :)

Look here:

Java Code:
```import java.util.Random;

public class twodim {

public static void findEven() {
for (int x = 2; x <= 20; x = x + 2) {
System.out.println(x);
}

for (int y = 2; y <= 20; y = y + 2) {
System.out.println(y);
}
}

public static void main(String[] args) {

final int row = 4;
final int col = 4;

Random rand = new Random();

int[][] twoDarray = new int[row][col];

for (int x = 0; x < twoDarray.length; x++) {

for (int y = 0; y < twoDarray[x].length; y++) {

twoDarray[x][y] = rand.nextInt(1000);
}
}

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

for (int j = 0; j < twoDarray[i].length; j++) {

System.out.print(twoDarray[i][j] + " ");

}
System.out.println();
}

}
}```  Reply With Quote

3. ##  Originally Posted by johnjacob Below I started trying to create a method for findEven but ran into some problems with it when I tried to compile.
Which tells us absolutely NOTHING.

And your code is in very bad shape. Where is the method name? Inside brackets? No opening/closing braces for method. Where have you declared the x and y variables that you are using inside your for loop?

Read some basic stuff first : Trail: Learning the Java Language

Goldest  Reply With Quote

#### Tags for this Thread

arrays, even numbers, find, method, two dimensional arrays #### Posting Permissions

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