Answers for "initialize 2d array java"

10

how to print a 2d array in java

for (int row = 0; row < arr.length; row++)//Cycles through rows
{
  for (int col = 0; col < arr[row].length; col++)//Cycles through columns
  {
    System.out.printf("%5d", arr[row][col]); //change the %5d to however much space you want
  }
  System.out.println(); //Makes a new row
}
//This allows you to print the array as matrix
Posted by: Guest on April-22-2020
6

arrays sort 2d array java

Arrays.sort(myArr,(double[] a,double[] b)->{
                //here multiple lines of code can be placed
                return a[0]-b[0]; 
            });
Posted by: Guest on July-08-2020
1

Java 2d array initialization

class TwoDimensionalArray {

    public static void main(String[] args) {
        String[][] salutation = {
            {"Mr. ", "Mrs. ", "Ms. "},
            {"Kumar"}
        };

        // Mr. Kumar
        System.out.println(salutation[0][0] + salutation[1][0]);

        // Mrs. Kumar
        System.out.println(salutation[0][1] + salutation[1][0]);
    }
}

The output from this program is:

Mr. Kumar
Mrs. Kumar
Posted by: Guest on March-29-2021
0

how to initialize one dimensional array in java

int[] a; // valid declaration
int b[]; // valid declaration 
int[] c; // valid declaration
Posted by: Guest on January-08-2021

Code answers related to "initialize 2d array java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language