[java]第一阶段测试题-含答案
第一阶段测试题
1、以下是冒泡排序算法,从大到小的排序,请在相应空格地方进行填空:
public class BubbleSort
{
public static void main(String[] args){
int score[] = {67, 69, 75, 87, 89, 90, 99, 100};
for (int i = 0; i < score.length -1; i++){
for(int j = 0 ;j < length-i-1 ; j++){
if( score[j] < score[j+1] ){
int temp = score[j];
score[j] = score[j+1] (4) ;
score[j + 1] = temp;
}
}
}
}
}
2、请问如下代码每个赋值是否正确,请说出错误的编号,并说明原因。
public static void main(String[] args){
char v1=16;
short v2=16;
int v3=32;
float v4;
char q1=v1+v2; ―――――(1)错。四则运算至少结果为4字节,所以要强转。
short q2=v1-v2; ―――――(2)错。同上。