日期:2014-05-20 浏览次数:20844 次
public final class test {
public static void main(String[] args) {
System.out.println(single());
}
public static String single(){
StringBuffer sb = new StringBuffer();
Scanner input = new Scanner(System.in);
System.out.println("输入一串字母");
if (input.hasNext()) {//这里虽然判断了是否输入即是否为null。但是scanner控制台输入我还真不知道如何触发他为false的情况。。。
String sth = input.next().trim();//这里获取控制台输入的字符串的时候进行了去空格处理。
for (int i = 0; i < sth.length(); i++) {
int count = 0;
for (int j = 0; j < sth.length(); j++) {
if (sth.charAt(i) == sth.charAt(j)) {
count++;
}
}
if (count == 1) {
sb.append(sth.charAt(i));
}
}
return sb.toString();
}
return "丫什么都没输入我给你判断什么?!";
}
}
------解决方案--------------------
第一题
public class Test {
/**
* @Function:
* @Since Oct 12, 2011
* @param args
*/
public static void main(String[] args) {
String str = "abcbcefg";
for(int i = 0 ; i < str.length();i++){
if(str.indexOf(str.charAt(i)) == str.lastIndexOf(str.charAt(i))){
System.out.println(str.charAt(i));
break;
}
}
}
}