/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int[][] ia = new int[3][3];
		ia[0][0] = 1;
		ia[0][1] = 1;
		ia[0][2] = 1;
		ia[1][0] = 4;
		ia[1][1] = 4;
		ia[1][2] = 2;
		ia[2][0] = 5;
		ia[2][1] = 6;
		ia[2][2] = 7;
		findRepeats(ia, 9);
	}
	
	public static void findRepeats(int [][] num, int size)
{
    int findNum;
    int total = 1, row = 0, col = 0;
    int [] check = new int[size];
    while(row < num.length && col < num[0].length)
    {
        //Set to number
        findNum = num[row][col];
      //Cycle array to set next number
        if(col < num[0].length-1)
            col++;
        else
        {
            row++;      //Go to next row if no more columns
            col = 0;    //Reset column number
        }
        //Loop through whole array to find repeats
        for(int i = row; i < num.length; i++)
        {
            for(int j = col; j < num[i].length; j++)
            {
                if(num[i][j] == findNum) {
                    total++;
                     //Cycle array to set next number
                      if(col < num[0].length-1)
                          col++;
                      else
                      {
                           row++;      //Go to next row if no more columns
                           col = 0;    //Reset column number
                      }
                      if(row < num.length - 1 && col < num[0].length -1)
                         num[i][j] = num[row][col];
                }
            }
        }


        //Display total repeats
        System.out.println("Number " + findNum + " appears " + total + " times.");
        total = 1;
    }
}
}