当前位置:文档之家› 传智播客 JAVA基础知识测试 初测(带答案)

传智播客 JAVA基础知识测试 初测(带答案)

20. 下面程序执行的结果 for(int i=1;i<=10;i++) {
if (i<5) continue;
System.out.println(“java 基础班”); } 在屏幕上打印几次 java 基础班? ( ) A. 5 B. 6
C. 7 D. 8
21.阅读下面代码段: public class Demo {
29. 下列代码执行的结果为( ) class Demo {
public static void main(String[] args) {
int num = max(43,34); System.out.println(num); }
public static int max(int a,int b) {
System.out.println("d"); A. a B. true C. c D. d
19. 下面程序执行的结果是?( ) int x=2,y=3; switch(x) {
default: y++; case 3: y++; case 4: y++;
} Sysetem.out.println("y="+y); A. 3 B. 4 C. 5 D. 6
return a>b?a:b;
} }
A. 43 B. 23
C. 77 D. 9
30 .下面程序执行的结果是( ) Class Demo {
public static void main(String [] args) {
int a=10; if(a++>10) {
a=20; }
System.out.println(a); } } A. 11 B. 12 C. 20 D. 21
7. 下面程序执行的结果是?( ) public class Test() {
public static void main(String[] args) {
System.out.println(“”+’a’+1); } } A. 98 B. a1 C. 197 Nhomakorabea. 971
8. 下面程序的运行结果是 ( ) int a=3, b=1; if(a==b)
答题格式:
1 - 30 题为单选题, 31 - 40 为多选题.
新建一个 txt 文件, 答案写在这个文件中.
答案必须保存为 txt 格式的文件。
答题的时候,可以在 EditPlus 上答题,会自动显示题目序号
文件名改为自己的名字,
每题一行.
多选题按 abcd 的顺序填答案, 比如某一题的答案 acd, 就必须是 acd, 不能是 adc 等等.
continue; sum+=i;
} System.out.println(sum); A. 55 B. 45 C. 35 D. 30
25. 下列语句中执行跳转功能的语句是( ) A. for 语句 B. while 语句 C. continue 语句 D. switch 语句
26. 在 switch(expression)语句中,expression 的数据类型不能是( ) A. double //byte short char int B. char
23.阅读下面代码段: public class Test {
public static void main (String[ ] args) {
char ch=’c’; switch (ch) {
case ‘a’: System.out.print(“a”);
break; case ’b’:
System.out.print(“ab”); case ’c’:
17. 阅读下列代码: public class Test {
public static void main ( String []args ) { int f=12; int i = 3; System.out.println( f /i ); }
} 程序运行结果为 ( ) A. 3 B. 3.0 C. 4 D. 4.0
22 .和下面代码能完成相同的选项是( ) int i=1; int sum=0; while(i<=100) {
if(i%2==0) //i 为偶数 {
sum=sum+i; } i++; }
A. for (int x =1; x<=100;x++){ sum=sum+x;} B. for (int x =0; x<=100;x+=2){ sum=sum+x;} C. for (int x =1; x<=100;x+=2){ sum=sum+x;} D.上述全对
public static void main (String[] args) {
int[] arr = new int [10]; System.out.println(arr[1]); } } 执行结果正确的说法是( ) A. 编译时将产生错误 B. 输出零 C. 编译时正确,运行时将产生错误 D. 输出空
33. 下面哪些语句可以通过编译 ( ) A. float a= 1.34f; B. float b=1.0; C. float c=2f; D. float d=20;
34. 下列函数中能和函数 int max(int a, int b, double c)构成重载关系的是( ) A. double max(int a, int b, double c) B. void max(int a, double c, int b) C. int max(int x, int y, double z) D. int max(double a, int b)
System.out.print(“c”); default:
System.out.print(“d”); } } } 输出的结果为 ( ) A. a B. b C. c D. cd
24. 以下代码输出是( ) int i=0; int sum=0; while(i<=10) {
i++; if( i%2 !=0 )
28. 下列代码中,将引起编译错误的行是( )。
1)public class Exercise{
2) public static void main(String []args){
3)
float f=0.0;
4)
f+=1.0;
5)
}
6) }
A. 第 2 行
B. 第 3 行
C. 第 4 行
D. 第 6 行
System.out.println("a="+a); A. a=1 B. a=3 C. 正常运行但没有输出 D. 编译错误
9. 下面程序的运行后,a,b,c 的值正确的是:( ) int a=1,b=2; int c=(a+b>3?a++:++b); A. a=2,b=3 B. a=1,b=3 C. a=1,b=2 D. c=2
11. 下面程序的运行结果( ) public class Demo {
public static int fun(int c) {
return c+=2; } public static void main(String[] args) {
int temp=fun(2); System.out.println(temp);
3. 下面哪个语句不会产生编译错误?( )
A. float a =2.0; //2.0f B. byte b =25; C. char c =”a”; D. boolean d=0;
4. 下面程序哪个语句是正确的 ( ) A. byte a=0,b=3; byte c =a+b; B. short s =23; s=s+12; C. float f = 23+23.23; D. short s=23; s+=12;
} } A. 2 B. 4 C. 6 D. 8
12. 下面程序的运行结果,哪个是正确的( ) int b=1; while(++b<3){
System.out.println("LOOP"); } A. 程序将会进入死循环导致无输出 B. 会输出多次 LOOP C 程序中含有编译错误 D. 输出一次 LOOP
x=7; }
System.out.println("x="+x+" , y="+y); A. x=1 y=2 B. x=7 y=1 C. x=7 y=2 D. x=2 y=2
15. 下面不属于基本数据类型的是( ) A. int B. double C. long D. int[] //引用类型
16. 给出下列代码: boolean a = false; boolean b = true; boolean c= ( a&&b)&&(!b); int result = (c == false)?1:2; 执行完后,c 与 result 的值是 ( ) A. false 和 1 B. true 和 2 C. true 和 1 D. false 和 2
C. byte D. short
27. 给出下列代码片段: if ( x > 0 ) { System.out.println(“Hello.”); } else if ( x >-3 ) { System.out.pirntln ( “ I am Tom. ”); } else { System.out.println (“How are you?”); } 请问将打印字符串 “How are you ?”的 x 的范围是( ) A. x>0 B. x > -3 C. x <= -3 D. x <=0 & x >-3
相关主题