• 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

String Array

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any body help me in this program .
(a)convert the whole String in lower case.
(b)Count the number of words which starts with a vowel.
(c)Retrieve the number of words and store them in an array.)
I wants to retrieve the number of words and store them in an array.
public class Assign1
{
public static void main(String[]args)
{
String s="I would like to be like an amitabachan. Kumar likes Julia Roberts.Pakistan is going to be super power next year.";int count=0;
//convert the whole string in lower case.
//count the number of words which starts with a vowel.
for(int i=0;i<s.length();i++)>
{
ch=Character.toLowerCase(s.charAt(i));
if (ch=='a' | | ch =='e'| | ch =='i'| | ch=='o'| | ch =='u')
count++;
}
System.out.println(s);
System.out.println(count);
System.out.println(s.length());
}
}
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at the methods in String and see StringTokenizer.
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sadaf
You should take your own brief specification and go through it one step at a time. Some hints:
for
(a) See java.lang.String.toLowerCase()
(b) See java.lang.String.startsWith()
(c) You need to loop through the String and check if each WORD starts with a vowel. Maintain a count of matches. When finished, you need an array of Strings to put matches into, which you have not created. What you are doing at the moment is counting the number of vowels in TOTAL, not the number of words starting with vowels.
Read up on the aforementioned methods of String and have another think about the problem. If you are still stuck, come back to us.
Hope this helps
Michael
------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic