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

print 2d array

2-D Vectors


vector<vector<int>> vect;

for (int i = 0; i < vect.size(); i++)
    {
        for (int j = 0; j < vect[i].size(); j++)
        {
            cout << vect[i][j] << " ";
        }   
        cout << endl;
    }
Comment

PREVIOUS NEXT
Code Example
Java :: spring data rest format time 
Java :: difference between offer and add in linkedlist in java 
Java :: spring data rest partial update 
Java :: traversing 2d array java 
Java :: java all alphabet characters 
Java :: java get keys from tree map 
Java :: how to collect objective in java 
Java :: Date from String java11 
Java :: list to observablelistz 
Java :: best ascii art characters 
Java :: java button actionlistener 
Java :: main method in java without static keyword 
Java :: decimal up to 6 places in java 
Java :: access main class from another class spigot 
Java :: how to iterate over a string in java 
Java :: java read string input 
Java :: android studio get string from strings.xml 
Java :: java sort 2d array 
Java :: java get first 3 characters of string 
Java :: How to efficiently multiply two numbers represented as Strings, in Java? 
Java :: Java forName() method 
Java :: create jframe java 
Java :: how to instantiate hashmap in java 
Java :: ++i vs i++ java 
Java :: print to console in java 
Java :: arrays.fill java 
Java :: change color of action bar android studio 
Java :: java log2 
Java :: java int to double 
Java :: java 11 download 64 bit 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =