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 the purpose of the operating systems management function
PIT_PIT [208]
The purpose of the operating systems is to provide an interface between the user and hardware. It's mange all resources, for example; memory, processors, and disk space. It's also mange how to file and store data in a computer system.
3 0
3 years ago
Normally, by the time teenagers have finished high school, they have formed their own identities and belief systems and have les
MaRussiya [10]

Answer:

The answer is rebellion

Explanation:

I took the test.

6 0
3 years ago
Help brainliest awnser
Kipish [7]

I am sure that both of those are right. I took technology classes all throughout middle school, and now I am in high school so.. I think, personally, that they are correct. Though, the last one might be B, considering they would have to type in the letters to make it appear. I am not 100% sure, but I definitely remember learning about this. Hope I helped! If I got it wrong, then at least I tried!

6 0
3 years ago
Your client has asked you to run an NMAP scan against the servers they have located in their DMZ. They would like you to identif
UNO [17]

Option D is the correct answer

nmap -O

Explanation:

  • DMZ means a demilitarized zone it will have more than 1 firewall to protect the server.
  • Nmap is the 1st step of ethical hacking in penetration testing for detecting the required detail from the server.
  • Nmap is used to scan the network and detect the host.
  • Nmap scanning can also be used to receive packets from the server without the trace of the client.
  • Nmap -O is used to detect the OS of the server and its version also.

5 0
3 years ago
A virus that loads itself onto the target system's memory, infects other files, and then unloads itself is called a:
prisoha [69]

Answer:

True. A virus that loads itself onto the target system's memory, infects other files, and then unloads itself is called a: Direct-action virus.

Explanation:

3 0
3 years ago
Other questions:
  • Assure that major, minor, sub1 and sub2 each contain four digit numbersIf less than four digits are entered in major OR minor OR
    5·1 answer
  • What was the impetus for corporations to begin entertainment broadcasting on radio?
    7·1 answer
  • Which cloud computing service model will enable an application developer to develop, manage, and test their applications without
    15·1 answer
  • What are the three business writing formats
    12·1 answer
  • Which of the following reflects Moore's law? Multiple Choice The doubling of computer chip performance per dollar every two year
    11·1 answer
  • My HTC Desire 510's mobile data stopped working, how to I make it work again?
    11·1 answer
  • To move an object to the bottom of the stack, click the Send Backwards arrow and then click Send to Back in the Arrange group on
    7·1 answer
  • How does Shakespeare immediately introduce Tybalt as a menacing character?
    9·1 answer
  • At year end, Clean123 Inc. has 45500 in cash, 55000 in accounts receivable, 54400 in service equipment, 550 in prepaid insurance
    12·1 answer
  • College entrance requirements are the expectations for admission.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!