import java.util.ArrayList;
import java.util.List;
public class Task7 {
static int count=0;
String arr[]=new String[40];
/**
*
* @param list
* @return an array consisting of vowels from the passed character array,
* in the order they appear. for example, if list = {'t','h','e','s','a','u','r','u','s'},
* the method returns {'e','a','u','u'}
*/
public static char[] getVowels(char[] list) {
//default return value so as to not get compilation error
//complete this method
/*
* HINT:
*
* Stage 1: count number of vowels in the passed array
* Stage 2: create an array of sufficient size
* Stage 3: add vowels to the created array
* Stage 4: return the populated array
*/
List<Character> a=new ArrayList<Character>();
char []vow=new char[30];
char[] soluc=null;
int count=0;
if(list==null)
{
System.out.println("You are passing null value");
return null;
}
for(int i=0;i<list.length-1;i++)
{
if(isVowel(list[i])==true)
{
a.add(list[i]);
vow[i]=list[i];
count ++;
}
}
System.out.println("number of vowels is"+count+"");
System.out.println("size is"+vow.length);
System.out.println("vowels are"+String.valueOf(vow));
System.out.println("size is"+vow.length);
System.out.println("array is"+a);
return vow;
}
/**
*
* @param c
* @return true if passed character is a vowel (upper, or lower case), and false otherwise
*/
public static boolean isVowel(char c) {
String vowels = "aeiouAEIOU";
return vowels.indexOf(c) >= 0; //c exists in the String vowels
}
public static void main(String[] args) {
// DO NOT MODIFY THIS METHOD
String s = "hi, this is lou! how are you?";
char[] a = s.toCharArray();
char[] b = getVowels(a);
System.out.println(b);
System.out.println(b.length);
}
}
Praveen_10 4 Junior Poster in Training
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.