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
Which of the following roles is responsible for writing programming code?
Georgia [21]
I would say the Software Engineer
7 0
3 years ago
Tom is not sure how to code contents such as title and meta elements. These are coded as ____ elements.
Naya [18.7K]

Answer:

Tom is not sure how to code contents such as title and meta elements. These are coded as <em>head</em> elements.

Hope that helps. x

8 0
2 years ago
Read 2 more answers
What is the difference between a status bar, title bar, and tabs?
Finger [1]

Answer:

Status Bar: a horizontal window at the bottom of a parent window in which an application can display various kinds of status information. The status bar can be divided into parts to display more than one type of information. The following screen shot shows the status bar in the Microsoft Windows Paint application.

Title Bar: horizontal bar at the top of a window, bearing the name of the program and typically the name of the currently active document.

Tabs: a tab is a clickable area at the top of a window that shows another page or area

7 0
2 years ago
Although some families have more resources than other families, there is always a limited amount of resources that families have
Shalnov [3]
True because some families can't afford very much
5 0
3 years ago
Read 2 more answers
What are the top 10 most dangerous computer viruses ?
Solnce55 [7]

Answer:

  • Mydoom
  • Sobig
  • Klez
  • ILOVEYOU
  • WannaCry
  • Zeus
  • Code Red
  • Slammer
  • CryptoLocker
  • Sasser

Explanation:

8 0
3 years ago
Other questions:
  • You can access various sites on the WWW by using hyperlinks or by
    14·1 answer
  • People use a computer connected to the internet to manage financial accounts
    15·1 answer
  • For each of the threats and vulnerabilities from the Identifying Threats and Vulnerabilities in an IT Infrastructure lab in this
    10·1 answer
  • Which part of a touchscreen responds to pressure applied to its surface?
    6·1 answer
  • Instructions
    8·1 answer
  • What is a common translator?​
    9·1 answer
  • Why do people make Among Us games on Ro-blox, and thousands of people play them, when Among Us is free on all devises?
    10·1 answer
  • Write a program to find the sum of first 10 even numbers in qbasic​
    15·1 answer
  • [If you were the queen of the world .... What would you change ?]
    14·1 answer
  • What will be the result from running the following program?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!