• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Array & String

 
Greenhorn
Posts: 2
  • 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]);
}
}
}
 
Sheriff
Posts: 9099
12
  • 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 ).
 
All of the following truths are shameless lies. But what about this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!