Look at the format specification you are using for your string. Compare it with the examples from the message where you originally posted this question.

The problem is very obvious.

Joanne

ramya narayanan

Ranch Hand

Posts: 338

posted 9 years ago

When I use printstream's(out) printf method it's somewhat working. But I need to manually calculate the whitespaces & issue printf accordingly with 8s , 9s ... Is there any other way i.e method so that strings can be automatically aligned.

Regards.

ramya narayanan

Ranch Hand

Posts: 338

posted 9 years ago

Now I've finally found it out how to get the desired output. I thank all the people. I've used printf method of printstream in achieving this.

output:

Try it out. %20s--> specifies that in that position which 20 spaces from the beginning a string value(specifically last letter of the first string) is going to come so that it can facilitate the alignment of subsequent strings . Consider these are the strings aaa,aaaa, aaaaaaa so what %20s will do is keep

%-10s--> 10 spaces from the backward similarly. Hope this is suffice. Regards.

[edited by: Campbell Ritchie. Add code tags around the aaa aaaa to preserve formatting. This may or may not align properly, depending on the font on people's browsers. ] [ December 10, 2008: Message edited by: Campbell Ritchie ]

ramya narayanan

Ranch Hand

Posts: 338

posted 9 years ago

How to use the String.format method in achieving the same output? Regards.

Well done getting it worked out . I think when I sent you and Ellen to the three format and one printf methods I gave all 4 links. If you read them, you find they use exactly the same parameters; if it works with one method, it will work with the same parameters with another.