In Java, how could I use printf() to both left justify and right justify output on the same line consistently? This is the code for everything left justified:
System.out.println(" ********************L********R");
String[] array = {"apple", "pie", "cheese"};
double[] array2 = {0.003, 1245, 19.979};
double[] array3 = {0.2, 1, 9};
for (int index = 0; index < array.length; index++)
{
System.out.printf(" %-10s%-10.2f%.2f%n", array[index], array2[index], array3[index]);
}
This is the output that everything is left justified:
********************L********R
apple 0.00 0.20
pie 1245.00 1.00
cheese 19.98 9.00
What I want instead if that for the third elements (0.20, 1.00, 9.00) to be right justified. I indicated in the output above that "L" is left justified, but I want the variables to be right justified where the "R" is. How can I right justify the output on the right (0.20, 1.00, 9.00), while also keeping the output on the left (apple, pie, cheese) left justified?