1

I have two arrays, one with String and the other one with int:

Create the arrays:

// Data //
     /* Marks array*/            static int[] marks = new int[3];
     /* Subject name array*/   static String[] subjects = new String[3];
// Data //

Make the user input 3 values into each array:

    for (int i = 0; i < subjects.length; i++)
    {
        System.out.println("Input the names of your subjects");
        subjects[i] = scan.next();
        System.out.println("");
    }                
    for (int i = 0; i < marks.length; i++)
    {
        System.out.println("Input your marks");
        marks[i] = scan.nextInt();
        System.out.println("");
    }

Ouput arrays:

    System.out.println(Arrays.toString(subjects));
    System.out.println(Arrays.toString(marks));

The code works and everything but the output is like this:

[Maths, History, French]
[10, 8, 6]

I want to make it so it displays like a table independently of the length of the values:

[Maths, History, French]
[   10,       8,      6]
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

0 Answers0