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

print two dimensional array java

//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 :: activitycompat.requestpermissions not working 
Java :: square root of a number in java without sqrt 
Java :: java check if number is in range 
Java :: check key is pressed java 
Java :: java int 
Java :: add opacity to activity android 
Java :: graph contains a cycle 
Java :: get request in java 
Java :: how to remove duplicate elements from char array in java 
Java :: java big integer to int 
Java :: pivot in array 
Java :: get frequency of letters java 
Java :: get raondom from array java 
Java :: main method 
Java :: Array list deep copy 
Java :: retainall java 
Java :: android application manifest 
Java :: how to change double to int in java 
Java :: how to get current date in java 
Java :: java gitignore 
Java :: java type casting 
Java :: java string not equal 
Java :: Using enum values as string literals 
Java :: how to change actionbar color in android programmatically 
Java :: java for loop increment by 3 
Java :: programmatically click button javafx 
Java :: Access items from the ArrayList using get() function 
Java :: get all keys from pbject javascirpt 
Java :: BufferredReader Class 
Java :: lombok maven plugin 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =