1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
irakobra [83]
3 years ago
12

We are building a word processor and we would like to implement a "reflow" functionality that full-justifies text.Given a maximu

m line width and an array containing lines of text, re-flow the text to fit the new width. Each line should be have the exact specified width. If any line is too short, insert spaces between words as equally as possible until it fits.
Computers and Technology
1 answer:
adoni [48]3 years ago
6 0

Answer:

The code is given below in Java with appropriate comments

Explanation:

Reflow is an function which helps you to justify your functionality

You need to input a string array and the max width and you will get the

output in a list(string).

public List<String> Reflow(String[] input, int width) {

   List<String> result = new ArrayList<String>();

 

   if(input==null || input.length==0){

       return result;

   }

 

 

   int count=0;

   int last=0;

   ArrayList<String> list = new ArrayList<String>();

   for(int i=0; i<input.length; i++){

       count = count + input[i].length();

 

       if(count+i-last>width){

           int wl = count-input[i].length();

           int sl = maxWidth-wl;

           int each = 1;

           int el = 0;

 

           if(i-last-1>0){

               each = sl/(i-last-1);

               el = sl%(i-last-1);

           }

 

           StringBuilder sb = new StringBuilder();

 

           for(int k=last; k<i-1; k++){

               sb.append(input[k]);

 

               int ce = 0;

               while(ce<each){

                   sb.append(" ");

                   ce++;

               }

 

               if(el>0){

                   sb.append(" ");

                   el--;

               }

           }

 

           sb.append(input[i-1]);//last input in the line

           //if only one word in this line, need to fill left with space

           while(sb.length()<width){

               sb.append(" ");

           }

 

           result.add(sb.toString());

 

           last = i;

           count=input[i].length();

       }

   }

 

   int lastLen = 0;

   StringBuilder sb = new StringBuilder();

 

   for(int i=last; i<input.length-1; i++){

       count = count+input[i].length();

       sb.append(input[i]+" ");

   }

 

   sb.append(input[input.length-1]);

   int d=0;

   while(sb.length()<maxWidth){

       sb.append(" ");

   }

   result.add(sb.toString());

 

   return result;

}

You might be interested in
The measure of error in keyboardist is called?​
Dimas [21]
Jjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
8 0
3 years ago
Who is using this website for edmentum tests?
babymother [125]

im using it for eddgenuity

3 0
3 years ago
Read 2 more answers
I have a problem with a task using scipy.optimize.minimize execution through the following methods: CG, BFG, Newton-CG, L-BFGS-B
Scilla [17]

Answer:

Touch and hold a clip to pin it. Unpinned clips will be deleted after 1 hour.

3 0
2 years ago
Does anyone know the answer to this question
koban [17]
The answer would be D) because they want the best of the best
7 0
3 years ago
Gilford is writing a paper about tigers. He notices that he has used the word “paws” many times. He would like to find a word he
Oksana_A [137]
The answer is C.) Thesaurus
8 0
3 years ago
Read 2 more answers
Other questions:
  • When you connect several home devices using a wireless router, what network topology are you using? A. bus B. mesh C. star D. ri
    9·1 answer
  • Software engineering design teams use ________, which are grounded in mathematical concepts of sets and relations, for their sof
    13·1 answer
  • A defined set of standards that computers must follow in order to communicate properly is known as a
    13·2 answers
  • Which term is used to describe a network security device or host software that filters communications, usually network traffic,
    14·1 answer
  • Explain why Windows and Linux implements multiple locking mechanisms. Describe the circumstances under which they use spinlocks,
    13·1 answer
  • Microsoft edge is a web browser that was designed as an add-in to internet explorer. true or false
    5·1 answer
  • The way that text and images are arranged on a slide is called _________. A. Layout B. Background C. Style D. Charting
    10·2 answers
  • Suppose that the instruction format for a modified Little Man Computer requires two consecutive locations for each instruction.
    5·1 answer
  • What symbol indicates that material has been copyrighted?
    8·2 answers
  • When you first purchase a notebook, make sure you have a ____ CD containing the installed OS so you can recover from a failed ha
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!