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 display 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

PREVIOUS NEXT
Code Example
Java :: java parallel sort 
Java :: how to print array 
Java :: java date with T 
Java :: how to check my java heap space size 
Java :: get month from int java 
Java :: java 8 filter first 
Java :: what is the use of println 
Java :: change height of row at JTable 
Java :: how to create an array list of ints in java 
Java :: convert int to hex java 
Java :: java 8 functional interfaces 
Java :: java string split from input string 
Java :: thymeleaf string not equal 
Java :: java prime numbers 
Java :: get current unix timestamp java 
Java :: print the list in java 
Java :: how to add elements to an empty array in java 
Java :: android studio Clearing shared preferences; 
Java :: java template string 
Java :: enum type spring boot entity 
Java :: copy to clipboard android studio 
Java :: hashmap iteration 
Java :: initialize hashset with values java 9 
Java :: how to send get request in java 
Java :: jframe change icon 
Java :: java read keyboard input 
Java :: printing prime numbers in java 
Java :: convert array of int to arraylist java 
Java :: java remove duplicates 
Java :: multiple type array java 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =