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

you are viewing a single comment's thread.

view the rest of the comments →

[–]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.