1

I am making a basic spreadsheet program, and by default I have the cell width set to 12 spaces. I am using printf to do this.

System.out.printf("%12s|", rowsAndColumns[i][j]);

How can I do something like.

System.out.printf("%cellWidths|", rowsAndColumns[i][j]);

Is this even possible?

Thanks.

3
  • 1
    See answers to How can I pad a String in Java?. Commented Dec 26, 2013 at 22:18
  • @Nick are you creating a spreadsheet that writes to the standard output? I think you ought to be using a GUI for that, isn't it? Commented Dec 26, 2013 at 22:19
  • The spreadsheet isn't using a GUI, its using print statements to print the rows and columns. Commented Dec 26, 2013 at 22:21

1 Answer 1

3

I don't think what you are looking for is possible.

But why don't you do it as follows -

System.out.printf("%" + cellWidths + "|", rowsAndColumns[i][j]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.