10: String contains the number of characters

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.