wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes String Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Array" Watch "String Array" New topic
Author

String Array

Sadaf Zaidi
Greenhorn

Joined: Oct 09, 2001
Posts: 29
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());
}
}
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Look at the methods in String and see StringTokenizer.
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
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


"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
 
GeeCON Prague 2014
 
subject: String Array