A
A
Amigo20192019-02-18 20:28:56
Java
Amigo2019, 2019-02-18 20:28:56

How to add a second array to the output in columns?

Good evening!
It is not possible to display both arrays, only one at a time. :-(

public class Marathon {


    public static String[] printResults(String[] names) {
        for (int i = 0; i < names.length; i++) {
            System.out.println(names[i]);
        }
        return names;
    }


    public static void main(String args[]) {
        String[] names = { "Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex", "Emma", "John", "James", "Jane", "Emily", "Daniel", "Neda", "Aaron", "Kate" };
        int[] times= { 341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265 };
        System.out.println("+----------+----------+" );
        System.out.println("|---NAME---|--RESULT--|" );
        System.out.println("+----------+----------+" );
        printResults(names);

    }
}

5c6aeb1ee4aef576826133.png
If anyone can help, then thanks in advance for the help and like :-)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-02-18
@Amigo2019

for (int i = 0; i < names.length; i++) {
  System.out.println(String.format(" %-11s%s", names[i], times[i]));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question