package com.lea.oops;
import java.util.HashMap;
import java.util.Scanner;
public class FirstNonRepeatedCharacter {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
char c = firstNonRepeatedCharacter(s);
System.out.println(c);
}
public static Character firstNonRepeatedCharacter(String str){
HashMap<Character, Integer> hashMap = new HashMap<Character, Integer>();
int i, length;
Character c;
length = str.length();
for (int j = 0; j < length; j++) {
c = str.charAt(j);
if (hashMap.containsKey(c)) {
hashMap.put(c, hashMap.get(c)+1);
}else{
hashMap.put(c, 1);
}
}
for (int j = 0; j < length; j++) {
c = str.charAt(j);
if (hashMap.get(c) == 1) {
return c;
}
}
return null;
}
}
import java.util.HashMap;
import java.util.Scanner;
public class FirstNonRepeatedCharacter {
/**
* @param args
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
char c = firstNonRepeatedCharacter(s);
System.out.println(c);
}
public static Character firstNonRepeatedCharacter(String str){
HashMap<Character, Integer> hashMap = new HashMap<Character, Integer>();
int i, length;
Character c;
length = str.length();
for (int j = 0; j < length; j++) {
c = str.charAt(j);
if (hashMap.containsKey(c)) {
hashMap.put(c, hashMap.get(c)+1);
}else{
hashMap.put(c, 1);
}
}
for (int j = 0; j < length; j++) {
c = str.charAt(j);
if (hashMap.get(c) == 1) {
return c;
}
}
return null;
}
}
No comments:
Post a Comment