Count characters Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1. Ex: If the input is: n Monday the output is: 1 n Ex: If the input is: z Today is Monday the output is: O z's If+beinniti.
Previous question

Respuesta :

To write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string.

What is string?

A string in computer programming refers to a group of characters, either as a literal constant or as a kind of variable. The latter may be fixed in length or may permit its elements to be altered (after creation).

A string is typically regarded as a data type and is frequently implemented as an array data structure made up of bytes (or words) that uses character encoding to store a sequence of elements, typically characters. Additionally, the term "string" can refer to more general arrays or other sequence (or list) data types and structures.

A variable that is explicitly declared to be a string may either result in memory being statically allocated for a predetermined maximum length or, depending on the programming language and precise data type employed, the opposite.

↓↓//CODE//↓↓

import

java.util.Scanner;

 public class

LabProgram

{

    public static void main(String[] args)

{

        Scanner scan = new Scanner(System.in);

        char userChar = scan.next().charAt(0);

        String userString = scan.nextLine();

         int result = 0;

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

            if(userString.charAt(i)==userChar){

                result += 1;

            }

        }

         if(result==1){

            System.out.println(result+" "+userChar);

        }

        else{

            System.out.println(result+" "+userChar+"'s");

        }

    }

}

Learn more about string

https://brainly.com/question/24275769

#SPJ4