HWOJ找出字符串中第一个只出现一次的字符

import java.util.Scanner; 
   
public class Main {  
   
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in); 
        boolean b = false;
        String str = sc.nextLine();
        char[] cs = str.toCharArray();
        for(int i = 0; i < cs.length; i++){
            if(str.indexOf(cs[i]) == str.lastIndexOf(cs[i])){
                System.out.println(cs[i]);
                b = true;
                break;
            }
        }
        if(!b){
            System.out.println('.');
        }
        sc.close(); 
    } 
}

推荐阅读更多精彩内容