mercredi 11 avril 2018

How to print an array using printf

Im currently trying to overload a method called printIntArray so that it accepts 2 parameters: the array and an integer, n, where n indicates the number of elements to be printed per line. I need to use printf and a right-justified field width of 5. If n <= 1, printing 1 element per line. What I have so far is:

public static void printIntArray(int a[ ], int n){

    if(n <= 1);
    System.out.printf(%5d);

How could I get the if statement to print the next one while using printf?

Aucun commentaire:

Enregistrer un commentaire