标签:eof char scanner size 数字 add sys system.in int
import java.util.ArrayList;
import java.util.Scanner;
public class Test8 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入:");
String number = input.next();
ArrayList<Character> arrayList = new ArrayList<Character>(); // 存放重复的数字;
char[] array = new char[String.valueOf(number).length()];
for (int i = 0; i < array.length; i++) {
array[i] = String.valueOf(number).charAt(i);
}
for (int i = 0; i < array.length; i++) {
for (int o = i + 1; o < array.length; o++) {
if (array[i] == array[o]) {
if (i == 0) {
arrayList.add(array[i]);
} else if (!isExist(arrayList, array[i])) {
arrayList.add(array[i]);
break;
}
}
}
}
for (int i = 0; i < arrayList.size(); i++) {
System.out.println("重复的数字是:" + arrayList.get(i));
}
}
public static boolean isExist(ArrayList<Character> arrayList, char num) {
for (int i = 0; i < arrayList.size(); i++) {
if (num == arrayList.get(i))
return true;
}
return false;
}
}
标签:eof char scanner size 数字 add sys system.in int
原文地址:http://www.cnblogs.com/L-zhihua/p/5988504.html