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
In this project, you will add a (self-proclaimed) priority attribute to xv6 processes. The priority does not actually do anythin
kondor19780726 [428]

Answer:

Priority programming is a process programming method based on priority. In this technique, the developer chooses the tasks to work according to priority, which is different from other types of programming, for example, a simple round-robin.

On UNIX and many other systems, higher priority values represent lower priority processes. Some of the systems, such as Windows, use the opposite convention: a higher number means a higher priority

<h3>Explanation: </h3>

Priorities can be dynamic or static. Static priorities are assigned during creation, while dynamic priorities are assigned according to the behavior of the processes while they are in the system. To illustrate, the planner could favor intensive input / output (I / O) tasks, allowing expensive requests to be issued as soon as possible.

Priorities can be defined internally or externally. Internally defined priorities make use of a measurable amount to calculate the priority of a given process. On the contrary, external priorities are defined using criteria beyond the operating system (OS), which may include the importance of the process, the type and sum of the resources used for the use of the computer, user preferences , trade and other factors such as politics etc.

i hope this is right lol

6 0
3 years ago
The faster the film (the higher the ISO), the more visible its grain. When you are using higher ISO, you are not just bringing g
NikAS [45]
I could not tell you
3 0
2 years ago
Read 2 more answers
Which game title went on to become the highest selling unbundled cartridge game?
alexandr402 [8]

Answer:

Tetris

Explanation:

On June 6, 1984, the first version of Tetris was unveiled and quickly took the world by storm. While Tetris has appeared on every major gaming platform from the Commodore 64 to the iPhone, it arguably gained its greatest notoriety as the cartridge game bundled with the original Nintendo Game Boy.

5 0
2 years ago
Which part of the processing unit does the logic operations?<br> A. ALC<br> B. CU
ycow [4]

isn't it ALU I got told it was ALU

4 0
3 years ago
Dam naj za pierwszej osobie która odpowie dobrze!
Rama09 [41]
I don’t understand that language
8 0
2 years ago
Other questions:
  • True or False, PDF documents have many benefits, but their main disadvantage is that the formatting of their text and graphic el
    15·1 answer
  • To create a formula, click the cell where you want to add the formula and press the _____ key.
    10·2 answers
  • Given an array arr of type int , along withtwo int variables i and j , write some code thatswaps the values of arr[i] and arr[j]
    6·1 answer
  • T F The exit function can only be called from main .
    10·1 answer
  • An application with which you can perform calculations on numbers and work with other data
    8·1 answer
  • During an upgrade for a new web server, Glen's company experienced a power surge. The power surge hit the new server, and now th
    10·1 answer
  • X274: Recursion Programming Exercise: Cannonballs Spherical objects, such as cannonballs, can be stacked to form a pyramid with
    7·1 answer
  • Importance of folders on a computer <br>​
    10·1 answer
  • Computer Graphics:
    13·1 answer
  • Describe the concept behind a digital signature and explain how it relates to cybersecurity by providing a hypothetical example
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!