Reputation: 125
How do I output a string but each part of the output can have a certain amount of characters? So say the first string gets 15 characters than the next gets another 15 and the same for the one after that?
Output
Output1 Output2 Output3
-------------------------------------------
String1 String2 String3
rather than where if String1000 has more characters than String1 it won't disrupt the outputs length
String1000 String2 String3
Upvotes: 2
Views: 278
Reputation: 39355
You can use the C
style printf in Java also. Here it is:
String x = "someString", y = "moreStringsss", z = "end";
System.out.printf("%-15s%-15s%-15s\n", x,y,z);
It outputs:
someString moreStringsss end
Upvotes: 1