Write a method called listUpper() that takes in a list of strings, and returns a list of the same length containing the same strings but in all uppercase form. You can either modify the provided list or create a new one.Examples:listUpper(list("a", "an", "being")) -> list("A", "AN", "BEING")listUpper(list("every", "gator", "eats")) -> list("EVERY", "GATOR", "EATS")listUpper(list()) -> list()In this format:public List listUpper(List list){}

Respuesta :

Answer:

//method listUpper takes a list of strings as parameter

public List<String> listUpper(List<String> list)

{ List<String> finalList= new ArrayList<String>();

//finalList is created which is a list to display the strings in upper case

for(String s:list){ //loop iterates through every string in the list and converts each string to Upper case using toUpperCase() method

s = s.toUpperCase();

finalList.add(s); } //finally the upper case strings are added to the finalList

return finalList; } //return the final list with uppercase strings

Explanation:

The method listUpper() works as follows:

For example we have a list of following strings: ("a", "an", "being").

finalList is a list created which will contains the above strings after converting them to uppercase letters.

For loop moves through each string in the list with these strings ("a", "an", "being"). At each iteration it converts each string in the list to uppercase using toUpperCase() and then add the string after converting to uppercase form to the finalList using add() method. So at first iteration "a" is converted to A and added to finalList, then "an" is converted to uppercase AN and added to finalList and at last iteration "being" is converted to BEING and added to finalList. At the end return statement returns the finalList which now contains all the string from list in uppercase form.

The method called listUpper() that takes in a list of strings, and returns a list of the same length containing the same strings but in all uppercase form is as follows:

def listUpper(list_string):

    for i in range(len(list_string)):

         list_string[i] = list_string[i].upper()

    return list_string

 

print(listUpper(["buy", "dog", "rice", "brought", "gun"]))

Code explanation

The code is written in python.

  • We declared a function named listUpper as required. The function takes in list_string as an argument.
  • Then, we loop through the range of the length of the list strings.
  • Then we make each looped value capitalise.
  • We returned the list strings.
  • Finally, we call the function with the required parameter.

learn more on python here: https://brainly.com/question/6858475