Saturday, November 9, 2024
HomeWordPress DevelopmentDecrease the utmost of Matrix whose rows and columns are in A.P

Decrease the utmost of Matrix whose rows and columns are in A.P


  

import java.io.*;

import java.util.*;

  

class GFG {

  

    

    public static ArrayList<ArrayList<Integer> >

    matrix(int A, int B)

    {

        ArrayList<ArrayList<Integer> > res

            = new ArrayList<ArrayList<Integer> >();

  

        

        

        if (A <= B) {

            for (int j = 0; j < A; j++) {

                ArrayList<Integer> temp

                    = new ArrayList<Integer>();

                for (int ok = 0; ok < B; ok++) {

                    temp.add(1 + (A + 1) * j

                             + (j + 1) * ok);

                }

                res.add(temp);

            }

        }

  

        

        

        else {

            for (int j = 0; j < A; j++) {

                ArrayList<Integer> temp

                    = new ArrayList<Integer>();

                for (int ok = 0; ok < B; ok++) {

                    temp.add(1 + (B + 1) * ok

                             + (ok + 1) * j);

                }

                res.add(temp);

            }

        }

        return res;

    }

  

    

    public static void fundamental(String[] args)

    {

        int A = 2;

        int B = 4;

  

        

        ArrayList<ArrayList<Integer> > ans

            = matrix(A, B);

        for (int i = 0; i < ans.measurement(); i++) {

            for (int j = 0; j < ans.get(i).measurement(); j++)

                System.out.print(ans.get(i).get(j) + " ");

            System.out.println();

        }

    }

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments