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
Software engineering design teams use ________, which are grounded in mathematical concepts of sets and relations, for their sof
zloy xaker [14]

Answer:

Relational Databases

Explanation:

These are digital databases that are made to recognize relations between previously stored items of info.

4 0
3 years ago
(e) The entries in each column of the array A are sorted into strictly increasing order.
gizmo_the_mogwai [7]
The answer is 3 because
5 0
2 years ago
Given an input array of strings (characters) s, pick out the second column of data and convert it into a column vector of data.
hodyreva [135]

Answer:

Consider the following code.

Explanation:

save the following code in read_and_interp.m

 

function X = read_and_interp(s)

[m, n] = size(s);

X = zeros(m, 1);

for i = 1:m

if(str2num(s(i, 2:5)) == 9999)

% compute value based on previous and next entries in s array

% s(i, 2:5) retrieves columns 2-5 in ith row

X(i,1) = (str2num(s(i-1 ,2:5)) + str2num(s(i+1,2:5)))/2;

else

X(i,1) = str2num(s(i,2:5));

end

end

end

======================

Now you can use teh function as shown below

s = [ 'A' '0096' ; 'B' '0114' ; 'C' '9999' ; 'D' '0105' ; 'E' '0112' ];

read_and_interp(s)

output

ans =

96.000

114.000

109.500

105.000

112.000

7 0
3 years ago
What type of device is characteristic of an enterprise environment?
Nitella [24]
A workstation used at an engineering firm.
8 0
3 years ago
Which of the following is not a technology that can be used to conserve resources?
amm1812
<span>Natural gas when extracted through human industry will utilise resources to construct the necessary plant and machinery and then result in the consumption of a resource. Therefore this is the technology that cannot be seen as conserving resources.</span>
6 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following criteria would not make a person eligible to receive medicare benefits?Which of the following criteria wo
    12·2 answers
  • For a loop counter, the appropriate data type would be:
    14·1 answer
  • Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar co
    10·1 answer
  • Is a router on the local network that is used to deliver packets to a remote network?
    15·1 answer
  • Which network component blocks status?
    9·1 answer
  • On a rheostat the first terminal is connected to a
    14·1 answer
  • Laptop computers use PCMCIA cards, another type of ________
    15·1 answer
  • I don't get the width and height part (PLEASE HELP WILL GIVE BRAINLIEST ANSWER)
    12·1 answer
  • Can a dod activity enter into a service contract for a military flight simulator without getting a waiver from the secretary of
    13·1 answer
  • Which of the following is an example of two-factor authentication?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!