18: Statistics of the number of characters

Source: Internet
Author: User

Title Description

Write a function that calculates the number of different characters contained in the string. The character is within the Acsii Code range (0~127). Not in the range of statistics.

Input Description: Enter n characters, character within acsii code range (0~127).

Output Description: The number of output characters.

Input Example: ABC

Output Example: 3

ImportJava.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner in=NewScanner (system.in); String input=In.nextline (); int[] Nums =New int[128]; intLength = 0;  for(inti = 0;i<input.length (); i++) {Nums[input.charat (i)]= 1; }         for(intj = 0;j<nums.length;j++)        {            if(Nums[j] = = 1) {length++;    }} System.out.println (length); }}

18: Statistics of 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.