📄 finddifferentball.java
字号:
package my_temp_work;
public class FindDifferentBall {
public static int compare(int goal, int index) {
int temp = 100;
int[] ball = new int[12];
for(int i=0;i<ball.length; i++) {
ball[i] = 1;
}
ball[index] = goal;
int[] a = new int[4];
int[] b = new int[4];
int[] c = new int[4];
for(int i=0; i<a.length; i++) {
a[i] = ball[i];
b[i] = ball[a.length+i];
c[i] = ball[a.length+b.length+i];
}
System.out.println("第一次判断:");
if(a[0]+a[1]+a[2]+a[3]==b[0]+b[1]+b[2]+b[3]) {
System.out.println("第二次判断:");
if(a[0]+a[1]+a[2]==c[0]+c[1]+c[2]) {
temp = c[3];
}else if(a[0]+a[1]+a[2]>c[0]+c[1]+c[2]) {
System.out.println("第三次判断:");
if(c[0]>c[1])
temp = c[1];
else if(c[0]==c[1])
temp = c[2];
else
temp = c[0];
}else{
System.out.println("第三次判断:");
if(c[0]>c[1])
temp = c[0];
else if(c[0]==c[1])
temp = c[2];
else
temp = c[1];
}
}else if(a[0]+a[1]+a[2]+a[3]>b[0]+b[1]+b[2]+b[3]) {
System.out.println("第二次判断:");
if(a[0]+a[1]+b[0]==a[2]+b[1]+c[0]) {
System.out.println("第三次判断:");
if(b[2]==b[3])
temp = a[3];
else if(b[2]>b[3])
temp = b[3];
else
temp = b[2];
}else if(a[0]+a[1]+b[0]>a[2]+b[1]+c[0]) {
System.out.println("第三次判断:");
if(a[0]==a[1])
temp = b[1];
else if(a[0]>a[1])
temp = a[0];
else
temp = a[1];
}else{
System.out.println("第三次判断:");
if(a[2]==c[0])
temp = b[0];
else
temp = a[2];
}
}else{
System.out.println("第二次判断:");
if(b[0]+b[1]+a[0]==b[2]+a[1]+c[0]) {
System.out.println("第三次判断:");
if(a[2]==a[3])
temp = b[3];
else if(a[2]>a[3])
temp = a[3];
else
temp = a[2];
}else if(b[0]+b[1]+a[0]>b[2]+a[1]+c[0]) {
System.out.println("第三次判断:");
if(b[0]==b[1])
temp = a[1];
else if(b[0]>b[1])
temp = b[0];
else
temp = b[1];
}else{
System.out.println("第三次判断:");
if(b[2]==c[0])
temp = a[0];
else
temp = b[2];
}
}
return temp;
}
public static void main(String[] args) {
int goal = 342;
for(int i=0; i<12; i++) {
System.out.println("The goal is: "+goal);
System.out.println("The result is: "+compare(goal, i));
System.out.println("-----------------------\n");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -