Respuesta :
Answer:
import java.util.ArrayList;
import java.util.List;
public class Vowels {
public static void main(String[] args) {
String word = "I am David from Nigeria";
System.out.println(which_vowels_present(word));
}
public static List which_vowels_present(String enteredWord){
List<Character>list = new ArrayList<>();
String word = enteredWord.toLowerCase();
for (int i =0; i<word.length(); i++){
if (word.charAt(i) == 'a' || word.charAt(i) == 'e' || word.charAt(i) == 'i'
|| word.charAt(i) == 'o' || word.charAt(i) == 'u') {
list.add(word.charAt(i));
}
}
return list;
}
}
Explanation:
- Using Java programming Language
- Import java.util.ArrayList; and java.util.List
- Create the method which_vowels_present which accepts a string parameter
- Within the method create a list object
- Use a for loop to iterate the string. within the for loop use an if statement to check individual characters of the string if any is a vowel, add it to the list
- return the list
- In the main method, create a test string, call the method and pass the string as parameter
Following are the program to the given question:
Program Explanation:
- Import package.
- Defining a class Main, inside the class main method is declared.
- Inside the main method, a scanner class object is created that inputs string value and pass into the method "which_vowels_present".
- In the "which_vowels_present" it takes one string parameter, inside the method list class object is created.
- In the next step, a string variable "s" is defined that converts string value into lowercase, and define a loop that uses if block to checks "vowels" value into the string and return the "l" value.
Program:
import java.util.*;//import package
public class Main //defining a class Main
{
public static void main(String[] args)//defining main method
{
String s;//defining String variable
Scanner objc=new Scanner(System.in);//creating Scanner class object
s=objc.next();//input value
System.out.println(which_vowels_present(s));//printing method value
}
public static List which_vowels_present(String w)//defining a method which_vowels_present that takes one String parameter
{
List<Character>l=new ArrayList<>();//creating list class object
String x= w.toLowerCase();//defining a String variable x that converts parameter value into LowerCase
for (int i =0; i<x.length(); i++)//defining a loop that
{
if (x.charAt(i) == 'a' || x.charAt(i) == 'e' || x.charAt(i) == 'i'|| x.charAt(i) == 'o' || x.charAt(i) == 'u') //defining if block that checks string value include vowels
{
l.add(x.charAt(i));//adding value in to list
}
}
return l;//return list value
}
}
Output:
Please find the attached file.
Learn more about function:
brainly.com/question/14305482
