• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array & String

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]);
}
}
}
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ).
 
reply
    Bookmark Topic Watch Topic
  • New Topic