I know how to format single variables, but I do not know how to format an array with printf(). I want to display my program with each number lining up with each other vertically, with each number on each line with the same amount of spaces. Below is an example of what I mean with different numbers:
1.1 2.2 3.3 4.4 5.5
1 2 3 4 5
Here is the code that I have for trying to display the numbers:
// create array
String[] tempsArray2 = temps2.toArray(new String[0]);
// for-each loop
for(String ss : tempsArray2){
// display ss to make sure program works correctly
System.out.printf("%40s", ss);
When I run it, the program displays like this:
run:
70.3 70.8 73.8 77.0 80.7 83.4 84.5 84.4 83.4 80.2 76.3 72.0
69 67 66 64 66 69 67 67 70 69 69 70BUILD SUCCESSFUL (total time: 0 seconds)
How can I fix this so that I can format the whole array once with a single System.out.printf(); statement, or do I have to format them one by one? Any help will be greatly appreciated.