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
To achieve balance—that is, to operate an information system that satisfies the user and the security professional—the security
marta [7]

the answer is True

there has to be a balance between security and the user experience

7 0
3 years ago
Match the following: B. Static libraries A. Dynamic Link Libraries (DLL) - Using static libraries - Making some changes to DLL A
TiliK225 [7]

Answer:  hello your question is poorly written and I have been able to properly arrange them with the correct matching

answer

Static libraries :  C

Dynamic link libraries:  A

Using static libraries:  B

Making some changes to DLL:   D

Explanation:

Matching each term with its meaning

<u>Static Libraries </u> : Are attached to the application at the compile time using the Linker ( C )

<u>Dynamic link libraries</u> ( DLL ) : Is Loaded at runtime as applications need them ( A )

<u>Using static Libraries </u>: Makes your program files larger compared to using DLL ( B )

<u>Making some changes to DLL </u>: Does not require application using them to recompile ( D )

8 0
3 years ago
One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input
salantis [7]

Answer:

import java.util.Scanner;

public class Miles {

public static void main(String[] args) {

   //initialization

       double Number_Miles;

       //print the message

       System.out.print("Enter the number of miles: ");

       Scanner scn1 = new Scanner(System.in);

       

       Number_Miles = scn1.nextDouble();  //read the input from user

       //calculate the laps

       double yourValue = Number_Miles/0.25;

       //display the output on the screen

       System.out.printf("%.2f", yourValue);

     

}

}  

Explanation:

First import the library Scanner than create the class and define the main function. In the main function, declare the variables.

print the message on the screen and then store the value enter by the user into the variable.

Scanner is a class that is used for reading the output. So, we make the object of the class Scanner and then object call the function nextDouble() which reads the input and store in the variable.

After that, calculate the number of laps by dividing the number of miles with the given one lap running track value (0.25 miles).

Number\,of\,laps = \frac{Number\,of\,miles}{0.25}

the output is stored in the variable.

After that, print the value on the screen with 2 digits after the decimal point.

we can use "%.2f" in the printing function in java.

like System.out.printf("%.2f", output);

5 0
3 years ago
Read 2 more answers
please help me!!!!!! all of the following may be benefits of a technical or vocational college except
-BARSIC- [3]

Answer:

im not sure

Explanation: is their supposed to be a picture or something?

5 0
3 years ago
Read 2 more answers
You can enter the following things in cells
katrin [286]

Answer:

You enter three types of data in cells: labels, values, and formulas.

Explanation:

I hope this is the right answer I knew it on top of my head but I made sure with goggle to.

3 0
2 years ago
Other questions:
  • What is the purpose of the “little down arrow” next to many different functions in word
    6·1 answer
  • The protocol that enables computers on the Internet to communicate with each other is called _____.
    7·1 answer
  • All spreadsheet formula should start with
    12·1 answer
  • Develop an sec (single error correction) code for a 16-bit data word. generate the code for the data word 0101000000111001. show
    6·2 answers
  • Missy creates a personal budget. She enters her current savings account balance in cell D3. In cell A3, she calculates her incom
    13·2 answers
  • A program that interacts with another piece of software as it if were a human user is known as a(n) ________.
    5·1 answer
  • Late at night, some traffic signals change patterns and become _____.
    9·2 answers
  • Danielle, a help desk technician, receives a call from a client. In a panic, he explains that he was using the Internet to resea
    9·1 answer
  • What is keylogging attack?
    13·2 answers
  • Which statement describes what the Conditional Formatting option in Excel 2016 allows users to do?
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!