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
spayn [35]
3 years ago
14

Write a function listLengthOfAllWords which takes in an array of words (strings), and returns an array of numbers representing t

he length of each word.
Computers and Technology
1 answer:
vesna_86 [32]3 years ago
7 0

Answer:

   public static int[] listLengthOfAllWords(String [] wordArray){

       int[] intArray = new int[wordArray.length];

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

           int lenOfWord = wordArray[i].length();

           intArray[i]=lenOfWord;

       }

       return intArray;

   }

Explanation:

  1. Declare the method to return an array of ints and accept an array of string as a parameter
  2. within the method declare an array of integers with same length as the string array received as a parameter.
  3. Iterate using for loop over the array of string and extract the length of each word using this statement  int lenOfWord = wordArray[i].length();
  4. Assign the length of each word in the String array to the new Integer array with this statement intArray[i]=lenOfWord;
  5. Return the Integer Array

A Complete Java program with a call to the method is given below

<em>import java.util.Arrays;</em>

<em>import java.util.Scanner;</em>

<em>public class ANot {</em>

<em>    public static void main(String[] args) {</em>

<em>       String []wordArray = {"John", "James", "David", "Peter", "Davidson"};</em>

<em>        System.out.println(Arrays.toString(listLengthOfAllWords(wordArray)));</em>

<em>        }</em>

<em>    public static int[] listLengthOfAllWords(String [] wordArray){</em>

<em>        int[] intArray = new int[wordArray.length];</em>

<em>        for (int i=0; i<wordArray.length; i++){</em>

<em>            int lenOfWord = wordArray[i].length();</em>

<em>            intArray[i]=lenOfWord;</em>

<em>        }</em>

<em>        return intArray;</em>

<em>    }</em>

<em>}</em>

This program gives the following array as output: [4, 5, 5, 5, 8]

You might be interested in
Angelina wants her text to look less crowded on the page, so she decides to decrease the length of the space the text occupies.
ratelena [41]

Answer:

She can go to the Layout tab and then to the Page setup command group to increase the margins of the page.

Explanation:

Because margin decides from the text should start ie. it decides how much space should be left on the top of the page, bottom, left and right. If you increase the margin automatically the amount of space in all the four sides gets increased and hence the contents gets automatically adjusted and the text will look better readable than before.

The crowd that it has created before automatically gets adjusted and will give a better look.

8 0
3 years ago
Read 2 more answers
The ____ tag is used to bring an image into a website. <br> (I need the blank for tag)
Montano1993 [528]
The *image* tag is used to bring an image on the website.
4 0
2 years ago
Read 2 more answers
How can you make the drawing tools contextual tab appear
Anestetic [448]

Answer:

Following up on Stefan's repsonse, this means that first, from the Insert tab you need to insert a line or shape. Once you've inserted something, select it and the contextual tab DRAWING TOOLS - FORMAT will appear.

Explanation:

3 0
2 years ago
Read 2 more answers
Which browser folder contains previously viewed web pages?
Arlecino [84]
<span>The history browser folder contains previously viewed web pages. This folder </span>stores the URLs of sites you have accessed within a defined period of time, which means you can see your browsing history.
<span> You can choose how you want to view the history by selecting a filter from the menu on the history tab.</span>
6 0
3 years ago
Write method reverseString, which takes a string str and returns a new string with the characters in str in reverse order. For e
son4ous [18]

Answer:

The method written in Java is as follows:

public static String reverseString(String str){

    String result = "";

    int lentt = str.length();

    char[] strArray = str.toCharArray();

       for (int i = lentt - 1; i >= 0; i--)

           result+=strArray[i];

    return result;

}

Explanation:

This defines the method

public static String reverseString(String str){

This initializes the result of the reversed string to an empty string

    String result = "";

This calculates the length of the string

    int lentt = str.length();

This converts the string to a char array

    char[] strArray = str.toCharArray();

This iterates through the char array

       for (int i = lentt - 1; i >= 0; i--)

This gets the reversed string

           result+=strArray[i];

This returns the reversed string            

    return result;

}

<em>See attachment for full program that includes the main method</em>

Download txt
3 0
2 years ago
Other questions:
  • What are the names of first generation computers?
    12·1 answer
  • What are the requirements of a data dictionary ?
    7·2 answers
  • The git _____ command will display the last commit and what were the changes you made.
    9·1 answer
  • What three steps Name a group??
    14·1 answer
  • Suppose arraylist list1 is [1, 2, 5] and arraylist list2 is [2, 3, 6]. after list1.addall(list2), list1 is __________.
    8·1 answer
  • During the ________ phase of the systems development life cycle process, developers construct, install, and test the components
    13·1 answer
  • Instructions:Select the correct answer.
    8·2 answers
  • Please help me I don't understand. It's Python.
    5·2 answers
  • A diagram of a ten-node network that uses ten routers
    11·1 answer
  • attackers typically use ack scans to get past a firewall or other filtering device. how does the process of an ack scan work to
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!