Results 1 to 4 of 4

Thread: [RESOLVED] Java Column Alignment ARGHHHHH!!!!!

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Resolved [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:

    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:

    public static void printProductDetails(Product product) {
    System.out.printf("%-8s %-8s %8s %8s \n", product.getCode(), product.getBrand(), product.getName(), product.getPrice(), '\n');
    }
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width