111k views
21 votes
The sameNumber method checks to see if the number of words in the phrase, numwords, is the same number of words contained in the myWords array. The method returns true of the array and phrase have the same number of words and false if they do not. Write the sameNumber method.

User Spittal
by
4.7k points

1 Answer

7 votes

Answer:

Answered below.

Step-by-step explanation:

//Program is written in Kotlin programming language.

fun sameNumber(numWords: String, myWords: List<String>) : Boolean{

//Split words in phrase into list

val str: List<String> = numWords.split(" ")

//Convert to mutable list.

val phrase = str.toMutableList()

val words = myWords.toMutableList()

//Compare the number of items in each list.

if( phrase.size == words.size){

return true

}else{

return false

}

}