Results 1 to 3 of 3
  1. #1
    johnjacob is offline Member
    Join Date
    Dec 2010
    Posts
    18
    Rep Power
    0

    Default 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();
                   }
    
               }
               }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    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();
    		}
    
    	}
    }

  3. #3
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Cool

    Quote Originally Posted by johnjacob View Post
    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
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

Similar Threads

  1. 2 dimensional array
    By sehudson in forum New To Java
    Replies: 5
    Last Post: 02-20-2011, 11:56 PM
  2. 2 dimensional array help!
    By ber1023 in forum New To Java
    Replies: 9
    Last Post: 01-02-2011, 12:29 AM
  3. Two dimensional array
    By niu_niu in forum New To Java
    Replies: 4
    Last Post: 06-13-2010, 12:34 AM
  4. about two dimensional array
    By matin1234 in forum New To Java
    Replies: 2
    Last Post: 06-01-2010, 11:09 AM
  5. two-dimensional array
    By kHim in forum New To Java
    Replies: 4
    Last Post: 11-16-2008, 07:21 PM

Tags for this Thread

Posting Permissions

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