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
As a student, why do you need to know and follow the steps printing a <br><br>document?​
Kazeer [188]
So I am able to print my math notes and keep up in geometry.
7 0
3 years ago
Read 2 more answers
43
pshichka [43]

Answer:

c

Explanation:

5 0
2 years ago
Read 2 more answers
4.2: Roman Numeral Converter
dalvyx [7]

Answer:

1 I

2 II

3 III

4 IV

5 V

6 VI

7 VII

8 VIII

9 IX

10 X

6 0
3 years ago
an attack has changed the value of a variable used when copying files from one cloud server to a local drive. what is the most l
BaLLatris [955]

Based in the provided information, The attacker utilized integer overflow attack which could bring alteration to the state of the local drive's memory.

<h3>What is an attack in computer terms?</h3>

An attack can be regarded as violation of one's data or information on the computer system.

Since, the attacker, changed the value of a variable used when copying files from one cloud server to a local drive, his motive was alteration to the state of the local drive's memory.

Learn more about attack on drive at;

brainly.com/question/11352260

5 0
3 years ago
Which of these expressions evaluates to 5.5?
muminat

Answer:

Being assigned the value 10

3 0
3 years ago
Other questions:
  • Assume that a two-dimensional rectangular array of integers called matrix has been declared with six rows and eight columns. Wri
    13·1 answer
  • What must you do when you save a file for the first time
    7·2 answers
  • A Portable Document Format (PDF) can be opened with Adobe Acrobat Reader and many web browsers.
    14·1 answer
  • What is the primary responsibility of the physical layer in data communication?
    8·1 answer
  • In 2 or 3 sentences, describe one advanced stradegy and how its useful
    11·1 answer
  • What do you mean by real time system? Why real time system needs to response within limited time?
    6·1 answer
  • What is ABC computer?​
    14·1 answer
  • What is the difference between a free-form outline and a modified outline?
    6·1 answer
  • Ali has created a small program in Python, but he wants to store his data in a multi-dimensional array. He would like to use adv
    8·1 answer
  • What kind of company would hire an Information Support and Service employee?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!