# Help with Two Dimensional Array

• 06-03-2011, 07:59 PM
johnjacob
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.

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();               }           }           }```
• 06-03-2011, 08:18 PM
eRaaaa
Oohhhh ...
public static void (findEven)
for (x = 2; x<= 20; x = x + 2) {

this is not a java syntax :)

Look here:

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();                 }         } }```
• 06-03-2011, 08:22 PM
goldest
Quote:

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