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
What is the connection between sites that allows for intersite replication called? (Points : 5) Bridgehead server
Travka [436]

Answer: Site Link

Explanation: Site link is the type connection that is created for the different sites.It helps in the connectivity in the multiple site surrounding known as inter-site and transferring the traffic created by the replication activity.

Other options are incorrect because bridgehead servers is a device to control the domain,subnet is the part of the IP network and domain is used for the identification of address .Thus, the correct option is site link.

4 0
3 years ago
If you are weak or lacking in an area or skillset, what kinds of things can you do to compensate or improve?
Ilya [14]
Put some more of your time to help improve that skill.try to learn to get better.
6 0
3 years ago
What is one way to overcome sad feelings?
laiz [17]

Answer:

music

Explanation:

it calms u and takes away all ur worries for that time because ur just vibing

4 0
2 years ago
Read 2 more answers
I. A teacher can prepare a slide and demonstrate it in the class with the help
marin [14]

Answer:

ay di ko alam yan hahahaha

3 0
2 years ago
A(n) _________________________ conveys a visual representation of data.
Komok [63]
I believe that the answer to fit this sentence is chart. Hope that this answer helped! ☺
3 0
3 years ago
Other questions:
  • In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the
    12·1 answer
  • AirPods se están despintando al ponerlos en quitaesmalte ayudaaaa?
    6·1 answer
  • Which topology enables only one person, at one time, to send data to others on the network?
    6·1 answer
  • What font option will elevate part of the text to a higher level and decrease its size? A. Subscript
    8·1 answer
  • The following types of websites are
    10·1 answer
  • Im bored, any anime recommendations? i probably watched whatever youre gonna say
    14·2 answers
  • Which graphics format works best for desktop publishing and print work? (1 point) .tiff .gif .tga .jpeg?
    11·1 answer
  • List two types of energy sources
    10·2 answers
  • Do earthquakes ever happen in Malaysia?​
    8·1 answer
  • Which of the following is a property of TCP?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!