473,417 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

How to write a static method for an array list.

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?

Expand|Select|Wrap|Line Numbers
  1. //import statement for ArrayList
  2. import java.util.ArrayList;
  3.  
  4. public class countingVowels {
  5.  
  6.  
  7.     public class VowelsProgram 
  8.     {
  9.         public static void main(String args[])
  10.         {
  11.             //create ArrayList that stores String object
  12.             ArrayList actor = new ArrayList();
  13.  
  14.             //add Indian actor names to above ArrayList
  15.             actor.add("Amitabh Bachan");
  16.             actor.add("Rajnikanth");
  17.             actor.add("Kamal Hassan");
  18.             actor.add("Shahrukh Khan");
  19.             actor.add("Akshay Kumar");
  20.  
  21.             //Write a loop statement that calls countingVowels method for each item in the ArrayList
  22.             //and prints number of occurrence of vowels in the item.
  23.              int aCounter = 0;
  24.              int eCounter = 0;
  25.              int iCounter = 0;
  26.              int oCounter = 0;
  27.              int uCounter = 0;
  28.  
  29.  
  30.              String line, temp;
  31.              int letter;
  32.  
  33.              for (int i=0; i<=letter; i++)
  34.  
  35.             if (line.charAt(i) == 'a')
  36.                  aCounter++;
  37.  
  38.                 else if (line.charAt(i) == 'e')
  39.                  eCounter++;
  40.  
  41.                 else if (line.charAt(i) == 'i')
  42.                  iCounter++;
  43.  
  44.                 else if (line.charAt(i) == 'o')
  45.                  oCounter++;
  46.  
  47.                 System.out.println ("Number of 'a': " +aCounter);
  48.                 System.out.println ("Number of 'e': " +eCounter);
  49.                 System.out.println ("Number of 'i': " +iCounter);
  50.                 System.out.println ("Number of 'o': " +oCounter);
  51.                 System.out.println ("Number of 'u': " +uCounter);
  52.  
  53.  
  54.         }
  55.  
  56.         //Write a static countingVowels method that accepts String as parameter.
  57.         //this method returns integer array contains count of vowels character
  58.         //occurrence in the parameter.
  59.  
  60. return ;
  61.     }
  62.  
  63. }
  64.  
Nov 4 '10 #1
1 5075
Dheeraj Joshi
1,123 Expert 1GB
You have following code posted.
Expand|Select|Wrap|Line Numbers
  1. int letter;
  2. for (int i=0; i<=letter; i++)
  3.  
You have letter declared but where is the initialization? What value does letter have?

Similar story with variable line of type String

Expand|Select|Wrap|Line Numbers
  1. String line, temp;
  2. if (line.charAt(i) == 'a')
  3.       aCounter++;
  4.  
There will be no String literal gets stored in the variable line.

Regards
Dheeraj Joshi
Nov 8 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: jonny | last post by:
Hey I need to search an array list to remove duplicate Data The list is populated by a search function that enters in a name if the it is told too This causes duplicate names to be entered...
2
by: Rene \(Programmer Wannabe\) | last post by:
Sorry for reposting this question, I asked this a couple of days ago but got no definite answer as to why the Array class behaves this way. Hope this time I will have better luck. Please read...
1
by: Phenix Smith | last post by:
I am looking at coverting an application over to C#. Currently I have a global list varible that needs to be converted. I have tested different ideas to accomplish the same idea. Ths best way I...
8
by: Fernando Lopes | last post by:
Hi there! Someone has some code sample about when is recommend use a statis method? I know this methos don't want to be initialized and all but I want to know when I need to use it. Tks....
6
by: rlvladbob | last post by:
Hi, I've try to access a static method using an instance instead of a class. public class test{ public static void ShowAText(string ThisText) { System.Console.WriteLine("->{0}",ThisText); }
3
by: Shawn H. Mesiatowsky | last post by:
I have an array list that I want to display to the browser. I need very precise control of the repeater, so I have function for the OnItemDataBound event for the repater, then in that function I...
10
by: steve bull | last post by:
I have a class SwatchPanel which takes Swatch as a parameter type. How can I call a static function within the Swatch class? For example the code below fails on TSwatch.Exists. How can I get the...
2
by: Rob Meade | last post by:
Dear all, I have a class which contains an arraylist populated with other objects, for example: PrescriptionQueue - containing multiple instances of Prescription I have the need on my web...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
12
by: Mark S. | last post by:
Hello, The app in question is lives on a Windows 2003 server with .NET 2.0 running IIS 6. The page of the app in question processes 2000 get requests a second during peak loads. The app uses...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.