我已经坚持了一段时间。我应该创建一个方法,计算有多少数字看起来是相同的。例如,7-2-2-7 应该给 2,4-4-5-5 应该给 2,而 1-2-3-4 给 0。但是我的程序给我 3 当只有2个不同的数字是相同的???帮助?
public class Help {
public static void main(String[] args) {
numRepeat(7, 2, 2, 7);
}//main
public static void numbers(int a, int b, int c, int d) {
int rep = 0;
int sum = 0;
for (int i = 0; i <= 1; i++) {
if (a == b || b == c || c == d) {
rep++;
sum += rep;
} else if (b == a || b == c || b == d) {
rep++;
sum += rep;
} else if (c == a || c == b || c == d) {
rep++;
sum += rep;
} else { /**do nothing**/ }
}//for loop
System.out.println("The sum of repeated digits is " + sum);
}//numRepeat
}//class