传智Java基础知识测试
共40道选择题,每题2.5分。多选题有错则全错,全对才满分.
A. int i=10;
B. float f=1.1;
C. double d=34.4;
D. byte b=127;
A. public
B. true
C. main
D. class
A. float a =2.0;
B. char c =”a”;
C. byte b =25;
D. boolean d=0;
A. byte a=0,b=3; byte c =a+b;
B. short s =23; s=s+12;
C. short s=23; s+=12;
D. float f = 23+23.23;
A. -128 ~ 127
B. -228 ~128
C. -255 ~ 256
D. -255 ~ 255
public class Test()
{
public static void main(String[] args)
{
System.out.println(“”+’a’+1);
}
}
A. 98
B. a1
C. 971
D. 197
int i = 100;
while(true)
{
If ( i++ > 100 )
break;
System.out.println(i);
}
A. 100
B. 101
C. 102
D. 103
int a=2;
switch(a)
{
case 1:
a+=1;
break;
case 2:
a+=2;
case 3:
a+=3;
break;
case 4:
a+=4;
break;
default:
a=0;
}
System.out.println(a);
A. 5
B. 6
C. 7
D. 8
int a=3, b=1;
if(a==b)
System.out.println("a="+a);
A. a=1
B. a=3
C. 编译错误
D. 正常运行但没有输出
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
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);
}
}
A. 2
B. 4
C. 6
D. 8
int b=1;
while(++b<3)
System.out.println("LOOP");
A. 程序将会进入死循环导致无输出
B. 输出一次LOOP
C. 会输出多次LOOP
D. 程序中含有编译错误
A. int [] arr ={23,45,65,78,89};
B. int [] arr=new int[10] ;
C. int [] arr=new int[4]{3,4,5,6};
D. int [] arr={‘a’, 23 , 45 , 6};
int x =1,y=1;
if(x++==2 & ++y==2)
{
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
A. int
B. double
C. long
D. int[]
boolean a = false;
boolean b = true;
boolean c= ( a&&b)&&(!b);
int result = (c = = false)?1:2;
执行完后,c 与 result 的值是( ).A
A. false和1
B. true和2
C. true和1
D. false和2
public class Test
{
public static void main ( String []args )
{
int f=12;
int i = 3;
System.out.println( f /i );
}
}
程序运行结果为( ). C
A. 3
B. 3.0
C. 4
D. 4.0
boolean b=true;
if(b=false)
{
System.out.println("a");
}
else if(b)
{
System.out.println(b);
}
else if(!b)
{
System.out.println("c");
}
else
System.out.println("d");
A. a
B. true
C. c
D. d
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
for(int i=1;i<=10;i++)
{
if (i<5)
continue;
System.out.println(“java基础班”);
}
在屏幕上打印几次java基础班?( )B
A. 5
B. 6
C. 7
D. 8
public class Demo
{
public static void main (String[] args)
{
int[] arr = new int [10];
System.out.println(arr[1]);
}
}
执行结果正确的说法是( )C
A. 编译时将产生错误
B. 编译时正确,运行时将产生错误
C. 输出0
D. 输出空
int i=1;
int sum=0;
while(i<=100)
{
if(i%2==0)
{
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 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’:
System.out.print(“c”);
default:
System.out.print(“d”);
}
}
}
输出的结果为( ) D
A. a
B. b
C. c
D. cd
int i=0;
int sum=0;
while(i<=10)
{
i++;
if( i%2 != 0 )
continue;
sum+=i;
}
System.out.println(sum);
A. 55
B. 45
C. 35
D. 30
A. for语句
B. while语句
C. continue语句
D. switch语句
A. double
B. char
C. byte
D. short
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的范围是( )C
A. x>0
B. x > -3
C. x <= -3
D. x <=0 & x >-3
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行
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)
{
return a>b?a:b;
}
}
A. 43
B. 23
C. 77
D. 9
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
以下题目为多项选择:
A. 2variable
B. variable2
C. what$
D. _3_
switch(i)
{
case1: System.out.println("message1");
case2:
case3: System.out.println("message2");
break;
}
A. 1
B. 2
C. 3
D. 4
A. float a= 1.34f;
B. float b=1.0;
C. float c=2f;
D. float d=20;
A. double max(int a, int b, double c)
B. void max(int a, double c, int b)
C. int max(double a, int b)
D. int max(int x, int y, double z)
A. int arr[] = new int[3];
B. int arr[] = new int[3]{1,2,3};
C. int [][]x = new int[][];
D. int[][] x = new int[2][];
int [] arr={23,54,76,87 };
for(int i=0;i<arr.length;i+=2)
{
System.out.println(arr[i]);
}
A. 23
B. 54
C. 76
D. 87
A. byte ,short,char 数据类型可以自动转化为int
B. float 数据类型可以自动转换为long。
C. 在java语言中默认小数为double
D. byte a=23; byte b=12; a+b的结果为byte类型
A. boolean b=true;
boolean b2=true;
if(b==b2) { System.out.println(“So true”); }
B. int i=0; if (i) { System.out.println(“Hi”); }
C. int i=1; int j=2; if(i==1|| j==2) System.out.println(“OK”);
D. int i=1; int j=2; if (i==1 &| j==2) System.out.println(“OK”);
A. 函数是对功能代码块的封装
B. 函数没有返回值的时候什么都不用写 àvoid
C. 没有返回值的函数,不能有return 语句
D. 函数是可以没有形参的
A. while循环先判断循环条件,后执行循环操作
B. while 至少会执行一次
C. do-while先进行循环条件判断,后执行循环操作
D. do-while循环至少执行一次,后进行循环判断