题目描述
给定一个英文字符串,请写一段代码找出这个字符串中首先出现三次的那个英文字符。
输入描述:
输入数据一个字符串,包括字母,数字等。
输出描述:
输出首先出现三次的那个英文字符
示例1
输入
Have you ever gone shopping and
输出
E
实现
public class Main {
publicstatic void main(String[] args) {
Scannerin = new Scanner(System.in);
while(in.hasNext()){
Strings = in.nextLine();
Map<Character,Integer>map =new LinkedHashMap<>();
for(inti=0;i<s.length();i++){
charc = s.charAt(i);
if(map.containsKey(c)){
intcount = map.get(c);
if(c>='a'&& c<='z' || c>= 'A' &&c<='Z'){
if(count==2){
System.out.println(c);
break;
}
}
map.put(c,count+1);
}else{
map.put(c,1);
}
}
}
}
}