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
Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are se
guapka [62]

void minMax(int a, int b, int c, int*big, int*small)

{

if(a>b && a >c){

*big = a;

if(b>c)

*small = c;

else

*small = b;

}

else if (b>a && b>c){

*big = b;

if(a>c)

*small = c;

else

*small = a;

}

else{

*big = c;

if(a>b)

*small = b;

else

*small = a;

}

}

8 0
2 years ago
which midi keyboard mode allows for one sound on one end of the keyboard and another on the other end
wlad13 [49]

Answer:

Sound button in the scratch

5 0
2 years ago
Write a MATLAB function named lin_spaced_vector with two inputs and one return value. The first input will be a single real numb
ycow [4]

Explanation:

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

lin_spaced_vector.m  

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

function out=lin_spaced_vector(in1,in2)%defining function

out=linspace(in1,in2,200);%200 spaced numbers between in1 and in2

end​

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

Executable File

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

clear all%clears history

clc%clears screen

lin_spaced_vector(1,10)%calling function​

clear all

clc

lin_spaced_vector(1,10)

4 0
3 years ago
Where can you find detailed information about your registration, classes, finances, and other personal details? This is also the
Andre45 [30]

Answer:

A. UC ONE Self-Service Center

Explanation:

The UC ONE Self-Service Center is an online platform where one can get detailed information about registration, classes, finances, and other personal details. This is also the portal where one can check class schedule, bill payment, viewing available courses, checking final grades, book ordering, etc.

it gives students all the convenience required for effective learning experience.

The UC ONE platform is a platform found in the portal of University of the Cumberland.

4 0
3 years ago
When is a handrail required for stairs
ch4aika [34]

Answer: when is not able to get up the stairs like a normal person

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • What is a database query?
    12·2 answers
  • Most keyboards today are in a
    8·1 answer
  • Which ipv6 router message is sent via multicast with a scope of link-local with the expectation that all local routers will iden
    5·1 answer
  • The Zoom slider will allow users to _____.
    5·2 answers
  • PLEASE HELP!<br> How do you "brainliest" an answer?
    13·2 answers
  • Assign a variable solveEquation with a function expression that has three parameters (x, y, and z) and returns the result of eva
    6·1 answer
  • The range A2:B4 has how many cells?   A. 2   B. 4   C. 6   D. 8
    11·2 answers
  • This is 6th grade career class.
    10·1 answer
  • Any my hero academia fans out there don't report at all just what more friends to
    14·2 answers
  • In which of the following movies, multimedia's special effect is used ? *
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!