Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array & String

 
ABDUL WARIS
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic