“Drucken Sie zwei Dimensionalarray 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 Sie zwei Dimensionalarray 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]);
	}
}
KeWols

Ähnliche Antworten wie “Drucken Sie zwei Dimensionalarray Java”

Fragen ähnlich wie “Drucken Sie zwei Dimensionalarray Java”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen