is that any good ideas to fixed the aligment of the output instead of using \t, due to some of the output words have more or less. :)

Recommended Answers

You can use the felxible printf method of PrintStream. You can use System.out to access it.
And you can specify exactly the number of columns each word must occupy using the C style format specifiers.

Jump to Post

All 3 Replies

but i can return method to display it? like use %.2f in C. :)
but i using using return method to display the output

public String toString(){
    	return "\t" + getFlavors() + "\t\t" + getWeight() + "\t\t\t" + getPrice() + "\t\t\t\t" + getQuantity() + "\t\t\t\t" + getPrice() * getQuantity();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.