Title Description: Write a program that accepts a string consisting of letters and numbers and spaces, and a character, and then outputs the number of characters in the input string. Case insensitive. Enter a description: Enter a string with letters and numbers and spaces, and a character. Output Description: The output input string contains the number of characters. Input example: Abcdefa Output Example: 1
Packageprctice01;ImportJava.util.Scanner;/*Title Description: Write a program that accepts a string consisting of letters and numbers and spaces, and a character, and then outputs the number of characters in the input string. Case insensitive. Enter a description: Enter a string with letters and numbers and spaces, and a character. Output Description: The output input string contains the number of characters. Input example: Abcdefa Output Example: 1*/ Public classnumofcharactorinstring { Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); String input= ""; String Sub= ""; Input=Scanner.nextline (); Sub=Scanner.nextline (); intCount = 0; Count=GetCount (input,sub); System.out.println ("The number of characters contained in the input string is:" +count); } Private Static intGetCount (String input, String sub) {if(Input.length () <=0)return0; intCount = 0; String inputstring=input.touppercase (); CharSubchar = Sub.touppercase (). CharAt (0); for(inti = 0;i<input.length (); i++) { if(Subchar = =Inputstring.charat (i)) Count++; } returncount; } }
10: String contains the number of characters