Respuesta :

ijeggs

Answer:

import java.util.Scanner;

public class ANot {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Please enter a word");

       String word = in.next();

       System.out.println("Please enter a character");

       char ca = in.next().charAt(0);

       int countVariable = 0;

       for(int i=0; i<word.length(); i++){

           if(ca ==word.charAt(i))

               countVariable++;

       }

       System.out.println(countVariable);

   }

}

Explanation:

  1. Using the Scanner Class prompt and receive the users input (the word and character). Save in seperate variables
  2. create a counter variable and initialize to 0
  3. Use a for loop to iterate over the entire length of the string.
  4. Using an if statement check if the character is equal to any character in string (Note that character casing upper or lower is not handled) and increase the count variable by 1
  5. print out the count variable