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
What is built on integrated circuits and carries the electrical current? CPUs Data Software Transistors
IrinaVladis [17]
The computer itself
6 0
3 years ago
The server core installation option in windows server 2012 effectively removes _______:
Stels [109]
Answer = <span>Graphical User Interface</span>
6 0
3 years ago
10. Write a function called replace_elem that takes an array and two values and uses the simple search
zalisa [80]

The function that replaces the values in an array is as follows:

def replace_elem(a, integer1, integer2):

    for i in range(len(a)):

         if a[i] == integer1:

              a[i] = integer2

    return a

print(replace_elem([7, 4, 10, 3, 7, 2, 4, 5], 4, 6))

<h3>Code explanation.</h3>

The code is written in python.

  • We defined a function named "replace_elem". The function accepts an array a, and integers integer1 and integer2.
  • Then, we used a loop to loop the index of the array.
  • If any of the index value is equals to the integer1, we replace it with integer2.
  • Then return the new values of the array a.
  • Finally, we call the function with its parameters.

learn more on function here: brainly.com/question/15691123

8 0
2 years ago
Google+ hangouts is connected to what other social media site?
Lynna [10]

Google Plus is the social media site that is connected with Hangouts.

 

To add, Google Plus<span> <span>is an interest-based </span></span>social network<span> <span>that is owned and operated by </span></span>Google. G<span>oogle's fourth foray into social networking, experienced strong growth in its initial years, although usage statistics have varied, depending on how the service is defined.<span> </span></span>

3 0
3 years ago
What is the features of Mark 1​
8090 [49]

Answer:

Okay:

Mark I was enourmous in size, measuring 8 feet high, 51 feet long and three feet deep. It weighed 5 tons, used 530 miles of wire and 730,000 separate parts. The operation of these parts was powered and synchronized by a long horizontal rotating shaft. A four horsepower engine drives the mechanical parts.

Harvard Mark I, an early protocomputer, built during World War II in the United States. While Vannevar Bush was working on analog computing at the Massachusetts Institute of Technology (MIT), across town Harvard University professor Howard Aiken was working with digital devices for calculation. He had begun to realize in hardware something like the 19th-century English inventor Charles Babbage’s Analytical Engine, which he had read about. Starting in 1937, Aiken laid out detailed plans for a series of four calculating machines of increasing sophistication, based on different technologies, from the largely mechanical Mark I to the electronic Mark IV.

5 0
3 years ago
Other questions:
  • If you have long column labels with columns so wide that they affect the readability of a worksheet, you should first
    15·2 answers
  • The__ key is used to group or identify a field or record within a table. (you don't need it).
    5·2 answers
  • According to the video, what qualities do Human Services workers need? Check all that apply.
    11·2 answers
  • Create a program that will read in a Salesperson name, employment status (1=Full-time AND 2=Part-time) and the sales amount.
    5·1 answer
  • 01110101<br> +00100100<br> 00010001
    8·1 answer
  • Which of these is an example of a system?
    7·1 answer
  • ________ was one of the first uses of the Internet
    15·2 answers
  • The ratio of boys and girls is 4:5 calculate the number of boys if the are 1080 learners in schools​
    11·1 answer
  • I really need help in this!!!
    11·1 answer
  • 24 3 Ans a. Define the term computer hardware. b. C. What are input devices? List any two input devices. What is processing devi
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!