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;
}
}
相关文章
- 07-31Java开发中经典的小实例-(while(参数){})
- 07-31Java开发中经典的小实例-(swich(){case:参数break;default: break;})
- 07-31Java开发中经典的小实例-(打印输入重复的值)
- 07-31Java开发中经典的小实例-(二分法)
- 07-31Java开发中经典的小实例-(能被3整除,并且十个数换一行)
- 07-31Java开发中经典的小实例-(比较输入数值的最大值、最小值和平均值)
- 07-31Java开发中经典的小实例-(do{}while())
- 07-31Java开发中经典的小实例-(随机数)
- 07-31Java开发中经典的小实例-(输入三个数字判断三角形类型)
- 07-31Java开发中经典的小实例-(字符串比较)