2015 Huawei Machine Test--print out the number of different characters in the string

Source: Internet
Author: User

Description:
Find out the number of different characters in the string.

Title Category: string
Difficulty: Beginner
Run time limit: Unlimited
Memory limit: Unlimited
Stage: pre-employment practice
Input:
Enter a string, ' + ' as the string terminator.

Output:
The number of different characters in the output string.

Sample input:
122345

Sample output:

5

The code is as follows:

public class Dayin_char{public static void Main (string[] args) {Scanner sc=new Scanner (system.in), while (Sc.hasnext ()) { String Input=sc.nextline (); if (input==null) {return;} int count=0; Map<integer,character> hm=new Hashmap<integer, character> (); for (int i = 0; i < input.length (); i++) {if (!h M.containsvalue (Input.charat (i))) {Count++;hm.put (I, Input.charat (i));}} System.out.println (count);}}}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

2015 Huawei Machine Test--print out the number of different characters in the string

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.