本期题目
常见笔试题:
下面代码的运行结果是什么?
class B extends Object{
static{
System.out.println("Load B1");
}
public B(){
System.out.println("Create B");
}
static{
System.out.println("Load B2");
}
}
class A extends B{
static{
System.out.println("Load A1");
}
public A(){
System.out.println("Create A");
}
}
publicclass Testclass {
publicstaticvoid main(String[] args) {
new A();
}
}
A、Load B1 Load B2 Create B Load A Create A
B、Load B1 Load B2 Load A Create B Create A
C、Load B2 Load B1 Create B Create A Load A
D、Create BCreate A Load A Load B1 Load B2
上期答案
对数组int[]arrays{1,4,2,3,9,5,6}进行排序,按照从大到小的顺序输出。(考虑使用冒泡排序)
packagecom.homework;
publicclass Test {
publicstaticvoid main(String[] args) {
int[]arrays={1,4,2,3,9,5,6};
int temp;
for (int i = 0; i < arrays.length-1; ++i) {
for (int j = arrays.length-1; j >i; --j) {
if(arrays[j]>arrays[j-1]){
temp=arrays[j];
arrays[j]=arrays[j-1];
arrays[j-1]=temp;
}
}
}
//遍历输出排序后的数组
for (int i = 0; i < arrays.length; i++) {
System.out.println(arrays[i]);
}
}
}
找我 Xxf960513