Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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
Comment

print 2d array in java

int[][] array = new int[rows][columns];
System.out.println(Arrays.deepToString(array));
Comment

java print two dimensional array

//this way u can print your array row by row

for (int i = 0; i < row; i++){
	for (int j = 0; j < column; j++){
        System.out.println(array[i][j]);
	}
}

//this way u can print your array column by column

for (int i = 0; i < column; i++){
	for (int j = 0; j < row; j++){
		System.out.println(array[i][j]);
	}
}
Comment

printing 2d array in java


public class Sample {
    public static void main(String[] args) {

        String roles[][] = {
                { "admin", "customer", "cashier", "manager" },
                { "Jasmine", "lyka", "marbie", "soleen" },
                { "mama", "papa", "jenilyn", "efren" }
        };
        for (int i = 0; i < roles.length; i++) {
            for (int j = 0; j < roles[i].length; j++) {
                System.out.println(roles[i][j] + " ");
            }
            System.out.println("");
        }
    }

}
Comment

java print 2d array as table

static void debugV2(Object... obj) {
        System.out.println(Arrays.deepToString(obj)
                .replace("],", "
").replace(",", "	")
                .replaceAll("[[]]", " "));
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj).replace("], ", "]
"));
    }
Comment

PREVIOUS NEXT
Code Example
Java :: how to stop screen rotation in android code 
Java :: how to hide status bar in android studio kotlin 
Java :: generate random string in java 
Java :: bukkit scheduler 
Java :: how to create progress dialog programmatically in android 
Java :: join array java 
Java :: how to measure the running time of a code section in java? 
Java :: internet permission in android studio 
Java :: prendere valore da tastiera java 
Java :: spring boot resource optional request param 
Java :: set text size programmatically android 
Java :: read jar manifest 
Java :: bubble sort java 
Java :: how to send file in request body rest assured 
Java :: android manifest internet permission 
Java :: java jtextfield text bold 
Java :: java double to string with 2 decimals 
Java :: java method to capitalize first letter 
Java :: display default value of auto commit java 
Java :: change date jdatepicker java 
Java :: bukkit chat format 
Java :: Bukkit debug message 
Java :: how to open whatsapp using an intent in your android app 
Java :: java initialize map with values in one line 
Java :: androidx.fragment.app.Fragment$InstantiationException 
Java :: java swing absolute position 
Java :: button color xml android 
Java :: setText int java 
Java :: jpa repository delete method return value 
Java :: discord jda get message by id 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =