“Array Java Imprimer 2D comme table” Réponses codées

Comment imprimer un tableau 2D en 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

Imprimez le tableau 2D en Java

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

Array Java Imprimer 2D comme table

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)

Java Imprimer 2D Row et colonne du tableau

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("\n"); //takes a new line before each new print
        }
    }
 }
Frightened Flamingo

Réponses similaires à “Array Java Imprimer 2D comme table”

Questions similaires à “Array Java Imprimer 2D comme table”

Plus de réponses similaires à “Array Java Imprimer 2D comme table” dans Java

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code