Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Question... methods

Chris99Chris99 Member Posts: 13
Hi. I need to write a method called countA that accepts a String parameter & returns the # of times the character 'A' is found in the string.


THANKS IN ADVANCE!

Comments

  • treshrtreshr Member Posts: 326
    The method must return a result, so you make a method similar like this:
    [code]
    public static int countChars(){

    }
    [/code]
    You have to get an argument with this method because you want specific String to be examined.
    You have to create a for loop that uses the "charAt" method that
    is part of the String API.
    charAt looks at the specific character at a certain point. The point is the "i" in a for loop, like this:
    [code]
    for(int i = 0; i < string.length; i++){

    }
    [/code]
    Make an "if" statement int the for loop that increases a integer variable every time the "charAt" finds a "A".

    Than the only thing you have to do is return the count variable.

    In another method create a integer variable that calls the just made method and gives a specific string with the method.

    I'm not gonna give you code, because I explained exactly what you have to, I hate if people ask for code because they are just too lazy to think of it themselves.

    Hope I helped you enouph.


    --=][tReShR][=--

Sign In or Register to comment.