others - java-获取乘法结果最后2位数字

135 5

下面的代码:


static void process(int array[]) {


 if (array.length <= 0) {


 System.out.println("-1");


 return;


 }


 int answer = array[0] % 100;



 for (int i = 1; i < array.length; i++) {


 answer = (answer * array[i] % 100) % 100;


 }



 System.out.println(answer);


}



有什么更好的方法来解决这个问题。

时间: 原作者:

111 5

代码示例:


static void process(int array[]) {


 if (array.length <= 0) {


 System.out.println("-1");


 return;


 }


 int answer = array[0] % 100;



 for (int i = 1; i < array.length; i++) {


 if(answer == 0) {


 break;


 }


 answer = (answer * array[i] % 100) % 100;


 }



 System.out.println(answer);


}



原作者:
116 1


boolean atLeast10 = false;


int answer = 1;


int i = 0;


for (; i < array.length && !atLeast10; i++) {


 if (array[i] == 0) {


 System.out.println(0);


 return;


 }


 answer = answer * array[i];


 if (answer >= 10)


 atLeast10 = true;


}


answer = answer % 100;


for (; i < array.length; i++) {


 if (array[i] == 0) {


 System.out.println(0);


 return;


 }


 answer = (answer * array[i] % 100) % 100;


}


if (!atLeast10 || answer >= 10)


 System.out.println(answer);


else


 System.out.println("0" + answer);



原作者:
...