OOP-JAVA Practical 11

OOP-JAVA Practical 11
  • Aim: Write a program that generate 6*6 two-dimensional matrix, filled with 0’s and 1’s , display the matrix, check every raw and column have an odd number’s of 1’s.
  • Code:
    public class practical11{
        public static void main(String[] args) {
           int i,j,count1=0,count2=0;
           int matrix[][] =new int[6][6];
           System.out.println("6*6 two dimensional matrix is : ");
           for(i=0;i<6;i++){
               for(j=0;j<6;j++){
                   matrix[i][j]=(int) (Math.random()*2);
                   System.out.print(matrix[i][j]+" ");
               }
               System.out.println();
           } 
           for(i=0;i<6;i++){
               for(j=0;j<6;j++){
                   if(matrix[i][j]==1){
                       count1++;
                   }
                   if (matrix[j][i]==1){
                       count2++;
                   }
               }
               if(count1%2!=0){
                   System.out.println("Row "+(i+1)+" contains odd number's of 1's");
               }
               if(count2%2!=0) {
                   System.out.println("Column "+(i+1)+ " contains odd number's of 1's");
               }
               count1=0;
               count2=0;
           }
       } 
    }
  • Output:
    Output of practical 11

Comments

  1. Sir please make video to explain this code

    ReplyDelete

Post a Comment