How to justify paragraph in java?


1/11/2019 1:36:34 AM

Harold Nocos

5 Answers

New Answer


An interesting question. What I would do for a problem like this is make a generalized algorithm for justifying text first. Something along the lines of the following: 1- Find out how long the line is 2- Find out how long the string is which is on that line 3- Calculate the number of spaces required to add to the string to equal the line length 4- Find out how many gaps there are between the words in the string 5- Calculate how many spaces we need to add to each gap in the string 6- Add result to each gap 7- Calculate how many extra spaces there are to serially add to each gap (only necessary if the number of gaps is not divisible by the number of spaces to add. For example if you have 3 gaps but 5 spaces to add) 8- Add extra spaces to gaps 9- Convert spaces to underscores 10- Return string Working off an algorithm is generally easier than trying to code a difficult problem.


great answer Ace ! also what I have observed in word processors is that the space is not of standard fixed width, but it is varying.


great !!!



can you make an example Sir? like autobiography