Counting unique characters in a String given by the user

前端 未结 12 1726
情书的邮戳
情书的邮戳 2021-02-15 17:42

I have to write a program that counts the uniques characters in a String given by the user. For example \"abc\" returns 3 and \"aabbccd\" returns 4. I am not allow to use advan

12条回答
  •  耶瑟儿~
    2021-02-15 18:20

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Please enter String:");
        int length = scanner.nextInt();
        char[] ch1 =  new char[length];
        String[] input = new String[length];
        for (int i = 0; i < length; i++) {
            String userInput = scanner.next();
            input[i] = userInput;
             ch1= userInput.toCharArray();
    
            Arrays.sort(ch1);
             System.out.println(ch1);
        }
    

提交回复
热议问题