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