1 Attachment(s)
[RESOLVED] Java Column Alignment ARGHHHHH!!!!!
Hey guys got a Java question for you.
I have finished coding (well thought I had finished coding) a program in java but the only problem is that it is giving me the correct input but it isn't in the columns properly.. an example picture has been attached to this post.
As you can see in the picture the column headings do not line up properly with the results. This is because of the word length of the results. I want to know how I can make everything move into pretty columns without having to shorten all the names (as that is not going to happen in the real world).
My code for printing the headings (Code, Brand, Name, Price) is:
Quote:
public void listProducts() {
System.out.printf("%-8s %-8s %8s %8s \n", "Code", "Brand", "Name", "Price");
for (int index = 0; index < productList.size(); index++)
printProductDetails(productList.get(index));
}
My code for printing the details is this:
Quote:
public static void printProductDetails(Product product) {
System.out.printf("%-8s %-8s %8s %8s \n", product.getCode(), product.getBrand(), product.getName(), product.getPrice(), '\n');
}
Re: Java Column Alignment ARGHHHHH!!!!!
Re: Java Column Alignment ARGHHHHH!!!!!
Thanks buddy, that's exactly what I needed :)
This issue has been resolved, I am lined up nicely now!
Re: Java Column Alignment ARGHHHHH!!!!!
Glad to hear that. Don't forget to mark the thread resolved from the "Thread Tools" menu