“Drucken von 2D -Array in Java” Code-Antworten

So drucken Sie ein 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
GelatinousMustard

Drucken Sie das 2D -Array in Java aus

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

Drucken von 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("");
        }
    }

}
Fernandez, Jasmine M.

2D -Array drucken

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;
    }
Alive Alligator

Java Print 2D -Array als Tabelle

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

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj).replace("], ", "]\n"));
    }
PRO_GrAMmER (IA Fahim)

Ähnliche Antworten wie “Drucken von 2D -Array in Java”

Fragen ähnlich wie “Drucken von 2D -Array in Java”

Weitere verwandte Antworten zu “Drucken von 2D -Array in Java” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen