我有这个问题,我应该编写代码并检查数组中数字的可分性,用数字(goodValue 和 badValue).. 如果好的和坏的值可以被数组中的数字整除,我们添加 +2 ,如果这个数能被好值整除,我们加1,如果这个值只能被坏值整除,我们减1。
public class Array {
static int[] ArrayA ={8, 4, 3, 12, 7, 9};
static int[] ArrayB ={3, 8, 14, 12, 10, 16, 6};
static int score;
public static void main(String [] args){
score = scoreArray(ArrayA, 2, 3);
System.out.println("First score for arrayA: " + score);
score = scoreArray(ArrayA, 3, 4);
System.out.println("Second score for ArrayA: " +score);
score = scoreArray(ArrayB, 5, 2);
System.out.println("First score for ArrayB: " +score);
score = scoreArray(ArrayB, 3, 7);
System.out.println("Second score for ArrayB: " +score);
}
private static int scoreArray( int [] theArray, int goodValue, int badValue){
for (int i=0; i<=theArray.length; i++){
if((i%goodValue & i%badValue)==0){
score=+2;
}
else if (i%goodValue==0){
score=+1;
}
else if((i%badValue==0)){
score= -1;
}
score+=score;
}
return score;
}
}
我应该得到这个
Firts score for arrayA: 1
Second score for arrayA: 3
First sccore for arrayB: -3
Second score for ArrayB: 2
我得到了这个
First score for arrayA: 2
Second score for ArrayA: 2
First score for ArrayB: 2
Second score for ArrayB: 2