Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a program and i wanted an output as a follow on the console

Java
ID               DESCRIPTION                  QUANTITY
--------------------------------------------------------
1                This is the first             10
                 product of our store
2                This is the second 
                 product of the program        20

and so on


I could format the other part of the thing except the description part. Overall what i want is that I want user to enter lets say 10 entry with a long description for each and display the output on the console in the same format as i have shown above. How do I accomplish the multiple lines description without jeopardizing the other part of the display no matter how long the description is.
Thanks
Posted
Updated 12-Sep-14 20:14pm
v2

1 solution

Look at the length of the description.
If it exceeds the available a space, look back for the last space that does fit and print up to there.
Print the quantity.
Remove the stuff you just printed from the string.
Space fill up to the description column, and repeat - not printing quantities this time.
 
Share this answer
 
Comments
xcelme 13-Sep-14 14:38pm    
There are many theory of how to accomplish it but I couldn't code the thing. If you can provide a pseudo-code then it would be great.
OriginalGriff 14-Sep-14 3:14am    
What part of the description above is giving you difficulty?
It's not exactly complex...
xcelme 16-Sep-14 0:57am    
I mean i tried using what you have said but doesn't quite work for me. Could you show me an code example on java
OriginalGriff 16-Sep-14 1:44am    
So show us what you have, and we'll see if we can spot the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900