aspose file tools*
The moose likes Ranch Office and the fly likes Array & String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » This Site » Ranch Office
Bookmark "Array & String" Watch "Array & String" New topic
Author

Array & String

ABDUL WARIS
Greenhorn

Joined: Oct 26, 2001
Posts: 2
Hi every one,
I am just a bigener in the field of java and having a problem that I am trying to solve the following:
1. Check if the first word starts with 'a'
2. Check if the first word starts with a vowel
3. Find the number of words in the String(given in question) starting with a vowel
4. After finding the number of words which starts with a vowel, retrive the found words and store them in an array and print
The first three I have successfully solved which show in the following code but the fourth one I tried my best but failed
I would request to please explain me to how to solve this
code:

class Waris2{
public static void main(String[]arga){
String text ="A Leader likes amitabh.Akbar loves julia roberts. Pakistan is one of most important country in south east asia region";
//1. Check if the first word starts with 'a'
text=text.toLowerCase();
System.out.println(text);
if(text.charAt(0)=='a'){
System.out.println("Yes it is");
}
//2. Check if the first word starts with a vowel
if(text.charAt(0)=='a'| |text.charAt(0)=='e'| |text.charAt(0)=='i'| |text.charAt(0)=='o'| |text.charAt(0)=='u'){
System.out.println("It is vowel");
}
System.out.println(text.length());
//3. Find the number of words in the String(given in question) starting with a vowel
int count = 0;
for(int i=0; i if(text.charAt(i)==' ' && (text.charAt(i+1)=='a'| |text.charAt(i+1)=='e'| |text.charAt(i+1)=='i'| |text.charAt(i+1)=='o'| |text.charAt(i+1)=='u'))
count++;
//System.out.println(count);
}
//4. After finding the number of words which starts with a vowel, retrive the found words and store them in an array and print
String []ss = new String[count];
for(int k = 0; k System.out.println("ss["+k+"]"+ss[k]);
}
}
}
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Seems like this has more to do with Java in General than with the JavaRanch site. I'm moving this to Java in General( beginning ).


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array & String