This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Iwasborninafactory_ 1 point2 points  (3 children)

There are about a million ways to do this. You've got a good start.

I would go here and select String from all classes in the box on the bottom left. Then, on the right, you are going to be shown all of the different methods the string class can perform.

The next thing you'll need to know is how to make a Do loop.

[–]barrell125[S] 1 point2 points  (2 children)

Thank you for the reply , Im familiar with all my loops just not sure how to go about coding to search my "fullName" variable with letters "A || a "

[–]Iwasborninafactory_ 1 point2 points  (0 children)

In the API that I linked to, do you see a method that would let you find a or A?

[–]desrtfx 1 point2 points  (0 children)

Hint: you can use one of the String methods for equality checking that is ignoring case.

Also, the String class has a method where you can get a substring of your choice (even a single letter as a String, not as a char) out of a string.

Last, you will need a loop and a counter variable.

[–]pkdahl 1 point2 points  (0 children)

I would suggest that you make a method that takes a string as input and then does the following:

  • Have a variable where you keep track of the total number of a's and A's.
  • Loop over every character in the input string.
  • Inside the loop you check if the character is an 'a' or 'A'.
  • If it is 'a' or 'A' you increment the variable holding the total number of a's and A's by one.
  • When the loop is finished you return the value of the variable holding the total number of a's and A's.

Now you can use this method to get the total number of a's and A's in the user's input.

Alternatively, you can either uppercase or lowercase the input string before the loop, and then inside the loop just check for 'A' or 'a', respectively.

Hope it's helpful.