Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need help wh a static method for an array. Posted by UNF_Steph on 4 Nov 2010 at 1:56 PM
I have created a vowel counting program and I'm not sure how to write the static method that accepts the String as a parameter. Can anyone help me write it?

//import statement for ArrayList
import java.util.ArrayList;
	
public class countingVowels {


	public class VowelsProgram 
	{
		public static void main(String args[])
		{
			//create ArrayList that stores String object
			ArrayList actor = new ArrayList();
			
			//add Indian actor names to above ArrayList
			actor.add("Amitabh Bachan");
			actor.add("Rajnikanth");
			actor.add("Kamal Hassan");
			actor.add("Shahrukh Khan");
			actor.add("Akshay Kumar");
			
			//Write a loop statement that calls countingVowels method for each item in the ArrayList
			//and prints number of occurrence of vowels in the item.
			 int aCounter = 0;
			 int eCounter = 0;
			 int iCounter = 0;
			 int oCounter = 0;
			 int uCounter = 0;
			 
			 
			 String line, temp;
			 int letter;

			 for (int i=0; i<=letter; i++)

			if (line.charAt(i) == 'a')
				 aCounter++;
				
				else if (line.charAt(i) == 'e')
				 eCounter++;
				
				else if (line.charAt(i) == 'i')
				 iCounter++;
				
				else if (line.charAt(i) == 'o')
				 oCounter++;

				System.out.println ("Number of 'a': " +aCounter);
				System.out.println ("Number of 'e': " +eCounter);
				System.out.println ("Number of 'i': " +iCounter);
				System.out.println ("Number of 'o': " +oCounter);
				System.out.println ("Number of 'u': " +uCounter);
			
				
		}

		//Write a static countingVowels method that accepts String as parameter.
		//this method returns integer array contains count of vowels character
		//occurrence in the parameter.

return ;
	}

}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.