Count occurrence of a number within 2d array [JAVA]

Discussion in 'Programming' started by homemadejam, Jul 17, 2009.

  1. #1
    Hey,

    I have a 2d array, currently with 10 rows, and 3 columns, but will soon be expanding.

    I need to count how many 0's are in each column, and store them as a separate integer. I have tried really hard on this, and I can just not figure it out!

    Now I know I will need something like:
    	for (int col = 0; col < Data.score[0].length; col ++) {
    	for (int row = 0; row < Data.score.length; row ++) { 
    
    		// Count 0's from each row, and save into separate int's
    	}
    	}
    
    Code (markup):
    As you can tell, I am still quite new to java...
    Any help would be extremely appreciated!
     
    homemadejam, Jul 17, 2009 IP
  2. adwall.asia

    adwall.asia Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Example for C++, not JAVA. Hope you'll get a liitle help.

    a[j]; //2D array
    arr[j];

    for (int col = 0; col < j; col ++) {
    for (int row = 0; row < i; row ++) {
    if(a[j] == '0')
    arr[j]= count++;
    }
    }
     
    adwall.asia, Jul 18, 2009 IP