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

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

java print 2d array row and column

public class TwoDimensionalArrays
{
public static void main (String args[])
{
    final int size1 = 2, size2 = 4, size3 = 5;
    int [][] numbers = {{20,25,34,19,33}, {11,17,15,45,26}, {27,22,9,41,13}};        
    int row = 0, col = 0;

        for(row = 0; row <= size1; row++); //loops through rows
        {
            for(col = 0; col <= size2; col++); //loops through columns
            {
                System.out.println(numbers[row][col]);
            }
        System.out.print("
"); //takes a new line before each new print
        }
    }
 }
Comment

PREVIOUS NEXT
Code Example
Java :: get arguments in fragment kotlin 
Java :: how to change a character in a string in java with ascii 
Java :: arraylist index java 
Java :: java string.format system.currenttimemillis 
Java :: java list get first element 
Java :: copying primitive array to arraylist in java 
Java :: how to unistall java 
Java :: button getsource 
Java :: prime number program in java 
Java :: breadth first search bst java 
Java :: how to add textview to listview in android 
Java :: create a hashmap 
Java :: android studio setBackground 
Java :: get spring application context 
Java :: How to get a context in a recycler view adapter 
Java :: java compute sum and average of array elements 
Java :: rock paper scissors java 
Java :: If you are using the git profile, you need to set a Git URI in your configuration. If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration. 
Java :: on item click listener for recyclerview adapter 
Java :: lowercase string java 
Java :: spring convert page to list 
Java :: Java get integer color from rgb 
Java :: java object into list 
Java :: how to convert errorBody to pojo in retrofit 
Java :: java map tostring 
Java :: Implementing the ArrayList Class in java list 
Java :: java android build secret keys 
Java :: object creation in java 
Java :: how to install clojure on linux 
Java :: variables in java 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =