1. 交换字符(无buffer)
public void swapNumWithoutBuffer(int a, int b) {
a = b - a;
b = b - a;
a = a + b;
System.out.println(a + " " + b);
}
2. 统计阶乘结尾0的个数public int getTailingZeros(int num) {
int count = 0;
for(int i = 0; num / i > 0; i *= 5) { //5的个数代表了结尾0的个数,注意25中有2个5,以此类推
count += num / i;
}
return count;
}
3. 统计整数数组中连续数字的最大和public int maxSequence(int[] array) {
int sum = 0;
int maxsum = 0;
for(int i = 0; i < array.length; i++) {
sum = array[i];
if(maxsum < sum) {
maxsum = sum;
} else if(sum < 0) { //一旦之前数字的和小于0,统计时候要把前面的内容去掉
sum = 0;
}
}
return maxsum;
}