1.main()方法的返回类型是:
A.int
B.void
C.boolean
java基础题选择
D.String
2.下列Java标识符,错误的是:
A.java3
B.java
C.3java
D.&java
3.下列程序编译或运行的结果是:
public static void main(String args[]) {
int a = 10;
int b;
int c;
if (a > 50) {
b = 9;
}
c = b + a;
System.out.println(c);
}
A.输出:10
B.输出:19
C.输出:9
D.编译出错
4.下列代码能正确编译的是:
A.public static void main(String[] args) {
int num = 100;
for(int i=0;i<=100;i++) {
int num = 10;
}
System.out.println(num);
}
B.public static void main(String[] args) {
int num = 100;
for(int i=0;i<=100;i++) {
num = 10;
}
System.out.println(num);
}
C.public static void main(String[] args) {
int num=0;
for(int i=0;i<=100;i++) {
num = 100;
}
for(int j=0;j<=100;j++) {
num = 200;
}
int num = 300;
System.out.println(num);
}
D.public static void main(String[] args) {
for(int i=0;i<=100;i++) {
int num = 100;
}
for(int j=0;j<=100;j++) {
int num = 200;
}
int num = 300;
System.out.println(num);
}
5.下列表达式错误的是:
A.double d=3.4;
B.double d=3.4d;
C.float f=1.2f;
D.float f=1.2;
6.下列语句片断中,four的值为:
int three=3;
char one='1';
char four=(char)(three+one);
A.3
B.1
C.31
D.4
7.关于下列程序片断,说法正确的是:
1)public class Test
2){
3)public static void main(String args[])
4){
5) byte b=100;
6) int i=b;
7) int a=2000;
8) b=a;
9) System.out.println(b);
}
}
A.b 的值为100
B.b 的值为2000
C.第6行出错
D.第8行出错
8.下列代码的运行结果是:
public static void main(String[] args) {
int a = 7;
System.out.println(a % 3);
}
A.2.0
B.2
C.1.0
D.1
9.以下程序的输出结果为:
public static void main(String args[]) {
int x=1,y=1,z=1;
if (x--==1&&y--==1||z--==1)
System.out.println("x="+x+",y="+y+",z="+z);
}
A.x=0,y=1,z=1
B.x=0,y=2,z=2
C.x=0,y=2,z=1
D.x=0,y=0,z=1
10.下列代码的输出结果是:
int a=10;
System.out.println(a<<2);
A.2
B.4
C.40
D.42
11.下列代码段编译和运行的结果是:
public static void main(String[] args) {
String str = "null";
if (str == null) {
System.out.println("null");
} else if(str.length() == 0) {
System.out.println("zero");
} else {
System.out.println("some");
}
}
A.null
B.zero
C.some
D.编译错误
12.下列代码段编译和运行的结果是:
public static void main(String[] args) {
int value = 0;
boolean setting = true;
String title = "Hello";
if (value || (setting && title == "Hello")) {
return 1;
}
if (value == 1 & title.equals("Hello")) {
return 2;
}
}
A.2
B.1
C.编译错误
D.可以运行,但无输出
13.以下代码段的输出结果为
int x = 0, y = 4, z = 5;
if (x > 2) {
if (y < 5) {
System. out .println ( "message one" );
}else {
System.out.println( "message two");
}
}else if (z > 5) {
System.out.println("message three");
}else {
System.out.println( "message four");
}
A.message one
B.message two
C.message three
D.message four
14.下列代码的运行结果是:
public class SwitchTest {
public static void main (String []args) {

System.out.println (“value =” +switchIt(4));
}
public static int switchIt(int x) {
int j = 1;
switch (x) {
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default:j++;
}
return j + x;
}
}
A.value =5
B.value =6
C.value =7
D.value =8
15.完成代码计算10的阶乘并输出,应该填入的代码是:
long result = 1;
for(int i = 2; i <= 10; i++) {
< 填入代码>
}
System.out.println("result= " + result);
A.result = result * i;
B.result = i*i;
C.result = i*(i+1);
D.reslut = i*(i-1);
16.请看下列代码:
public void go() {
String o = "";
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 2; y++) {
if (x == 1)
break;
if (x == 2 && y == 1)
break;
o = o + x + y;
}
}
System.out.println(o);
}
调用go方法,程序的输出结果是:
A.00
B.0001
C.000120
D.00012021
17.下面的程序没有编译错误的是:
A.public class Main{
public static void main(String[] args) {
byte b1 = 1;
byte b2 = 2;
byte b = b1+b2;
}
}
B.public class Main{
public static void main(String[] args) {
int n;
for(int i=0;i<10;i++) {
n +=i;
}
}
}
C.public class Main{
public static void main(String[] args) {
int n = 100;
for(;;) {
}
System.out.println(n);
}
}
D.public class Main{
public static void main(String[] args) {
int n = 100;
while(n>0);
System.out.println(n);
}
}
18.下列代码段的输出结果是:
public static void main(String[] args) {
int x = 0;
int y = 10;
do {
y--;
++x;
} while (x < 5);
System.out.print(x + "," + y);
}
A.5,6
B.5,5
C.6,5
D.6,6
19.下列数组定义及赋值,正确的是:
A.int[] ia = new int [15];
B.float fa = new float [20];
C.int ia [][] = (4, 5, 6) (1, 2, 3);
D.float[20] arr= new float[];
20.下列代码编译和运行的结果是:
public static void main(String[] args) {
String[] elements = { "for", "tea", "too" };
String first = (elements.length > 0) ? elements[0] : null;
System.out.println(first);
}
A.编译出错
B.输出:tea
C.输出:for
D.输出:null
21.请看下列代码:
public int print(String msg){
return 0;
}
print方法的使用正确的是:
A.int result=print(100);
B.String result=print(100);
C.int result=print("hello");
D.String result=print("hello");
22.下列代码的输出结果是:
public static void main(String[] args) {
int[] one=new int[]{4,6,8};
int[] two=new int[]{1,3,5,7,9};
System.arraycopy(one, 1, two, 3, 2);
System.out.println(Arrays.toString(two));
}
A.[1, 3, 7, 4, 6]
B.[1, 3, 5, 7, 8]
C.[1, 3, 5, 6, 9]
D.[1, 3, 5, 6, 8]
23.序列[78,45,98,46,23,55,12]进行插入排序时,第三趟排序的结果是:
A.[45, 78, 98, 46, 23, 55, 12]
B.[23, 45, 46, 55, 78, 98, 12]
C.[23, 45, 46, 78, 98, 55, 12]
D.[45, 46, 78, 98, 23, 55, 12]
24.序列[78,45,98,46,23,55,12]进行冒泡排序(轻泡上浮的方式)时,第三趟排序
的结果是:
A.[12, 78, 45, 98, 46, 23, 55]
B.[12, 23, 78, 45, 98, 46, 55]
C.[12, 23, 45, 46, 78, 55, 98]
D.[12, 23, 45, 78, 46, 98, 55]
25.台阶问题。楼梯有N阶,上楼可以一步上一价,也可以一次上二阶… 也可以一步
上n阶。使用递归算法,计算共有多少种不同的走法,下列选项正确的是:
A.public static int t(int n) {
if (n < 1) {
return -1;
} else if (n == 1)
return 1;
else if (n > 2)
return 2;
else
return t(n - 1) * t(n - 2);
}
B.public static int t(int n) {
if (n < 1) {
return -1;
} else if (n == 1)
return 1;
else if (n > 2)
return 2;
else
return t(n - 1) + t(n - 2);
}
C.public static int t(int n) {
if (n < 1) {
return -1;
} else if (n == 1)
return 1;
else if (n == 2)
return 2;
else
return t(n - 1) * t(n - 2);
}
D.public static int t(int n) {
if (n < 1) {
return -1;
} else if (n == 1)
return 1;
else if (n == 2)
return 2;
else
return t(n - 1) + t(n - 2);
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/2381.html