一些Java基础测试题目

1.         Java中,执行下面的语句后,c的值为()。

   String s= "Jessica ";

   char c=s.charAt(6);

a)                "c "

b)               "a "

c)                'c '

d)               'a '

 

2.         JAVA中下面哪一行代码不出现编译警告或错误( ).

a)         float f=1.3;

b)        char c="a";

c)         byte b=257;

d)        int i=10;

 

3.         Java中,调用Math.random() 方法可能返回的结果是()。

a)         132.34

b)        0.342

c)         29.34E10

d)        1.0009

 

4.         给定java代码片段,如下

Integer a = new Integer(3);

Integer b = new Integer(3);

System.out.println(a==b);

a)         True

b)        False

c)         0

d)        1

 

5.         下面是Java程序中的一些声明,选项中能够通过编译的一项是()。

String s1=new String(“Hello”);

String s2=new String(“there”);

String s3=new String();

a)         s3=s1+s2

b)        s3=s1&s2

c)         s3=s1||s2

d)        s3=s1&&s2


 

 

6.         编译并运行下面的Java代码段:

   char c='a';

   switch (c) {

     case 'a': System.out.println("a");

     default: System.out.println("default");

  }输出结果是()。(选择一项)

a)         代码无法编译,因为switch语句没有一个合法的表达式

b)        a    default

c)         a

d)        default

 

7.         Java,下列选项表示字符”a”值的是().(选择一项)

a)         'a'

b)        "a"

c)         new Character(a)

d)        /000a

 

8.         JAVA中,如果要在字符串类型对象S=“java”,中找出字母‘v’出现的位置(即位置2),可使用()。(选择一项)

a)         mid2s

b)        charAt2

c)         .s.indexOf(‘v’)

d)        .indexOfs,‘v’);

 

9.         JAVA编程中,Java编译器会将Java程序转换为()。(选择一项)

a)         字节码

b)        可执行代码

c)         机器代码

d)        以上所有选项都不正确

 

10.     给定某java程序片段,如下:

int i=1;

int j=i++;

if((i>++j)&&(i++==j))

i+=j;

System.out.println(i);

该程序运行后,i的输出结果为()。(选择一项)

a)         1

b)        2

c)         3

d)        4


 

 

11.     给定如下Java代码,编译运行时,以下(  )语句的值是true.(选择二项)

String s = “hello”;

String t = “hello”;

String e = new String(“hello”);

Char c{‘h’,’e’,’l’,’l’,’o’};

a)         s.equals( t );

b)        t.equals( c );

c)         .t.equals( e );

d)        t==c;

 

12.     java, 以下定义数组的语句正确的是( )  (选择一项)

a)         int t[10] = new int[]

b)        char a[] =”hefg”;

c)         int t[] = new int [10]

d)        double d = new int [10];

 

13.     JAVA, 无论测试条件是什么, 下列(  )循环将至少执行一次. (选择一项)

a)         For

b)        do…while

c)         while

d)        while…do

 

14.     定如下java代码, 编译运行之后, 将会输出(  ) (选择一项)

Public class Test {

       Public static void main(String args[]){

       int a = 5;

       System.out.println((a % 2 ==1)?(a+1)/2:a/2);

a)         1

b)        2

c)         2.5

d)        3

 

15.     .以下()不是Java的原始数据类型。(选择一项)

a)         .short

b)        boolean

c)         unit

d)        float


 

 

16.     给定一个Java程序的代码片断如下:       (选择一项)

If(grade==’A’||grade==’B’)

Score=90;

Else if(grade==’C’||grade==’D’)

Score=70;

Else

Score=60;

那一项代码与其很相同的功能。

a)         switch(grade){

               case ‘A’:

               case ‘B’:score=90;

               case ‘C’:

               case ‘D’:scpre=70;

               default:score=60;

              }

b)               switch(grade){

               case ‘A’:break;

               case ‘B’:score=90;

               case ‘C’:break;

               case ‘D’:scpre=70;

               default:score=60;break;

              }

c)         switch(grade){

               case ‘B’:score=90;break;

               case ‘D’:scpre=70;break;

               default:score=60;break;

              }

d)        switch(grade){

               case ‘A’:

               case ‘B’:score=90;break;

               case ‘C’:

               case ‘D’:scpre=70;break;

               default:score=60;break;

              }

 

17.     给定一个java程序的代码片断如下,运行后,正确的输出结果是()(选择一项)

String s=”hello, world”;

String str = s.replace(“,”   ,   ” ”);

System.out.println(str);

a)         hello world;

b)        hello, world

c)         HELLO WORLD

d)        HELLO ,WORLD;

18.  分析如下JAVA代码片段,输出结果为()。   (选择一项)

            int price = 10;

            int number = 0;

            int monney = 0;

            for (int i = 0;i<2;i++){

                   number++;

                   --price;

                   monney += number * price;

            }

            System.out.println(monney);

a)         25

b)        28

c)         31

d)        20

 

19.     给定一个 java 源程序 Test.java, 在命令行中 , 使用下面 (a)语句可以编译、运行该 程序。 ( 选择一项 )

a)         javac Test.java

java Test

b)        javac Test.java

java Ttest

c)         javac Test.java

              java Ttest

d)        javac Test.java javac Test.java

java Ttest

 

20. java程序中,main方法的格式正确的是()。(选择一项)

a)         static void main(String[] args)

b)        public void main(String[] args)

c)         public static void main(String[] s)

d)        public static void main(String args)

      

21.     给定java代码,如下:

public byte count(byte b1,byte b2){

            return______;

}

要使这段代码能够编译成功,横线处可以填入()。(选择一项)

a)         (byte)(b1-b2)

b)        (byte)b1-b2

c)         b1-b2

d)        (byte)b1/b2


 

 

22.     Java中,以下()标识符是不是合法的。(选择一项)

a)         IDoLikeTheLongNameClass

b)        $byte

c)         _ok

d)        4_case

 

23.     给定如下java代码, 编译运行之后, 将会输出(  ) (选择一项)

Public class Test {

       Public static void main(String args[]){

       int a = 5;

       System.out.println((a % 2 ==1)?(a+1)/2:a/2);

}

a)         1

b)        2

c)         2.5

d)        3

 

24.     给定一个Java程序代码,如下:运行编译后,输出结果是()

        public class Test{

             int count =9

              public void count1(){

                     int count = 10;

                     System.out.println(“count1=” + count);

        }

        public void count2(){

             System.out.println(“count2=” + count);

        }

        public static void main(String arge[]){

             Test t = new Test();

              t.count1();

              t.count2();

       }

   }

a)         count1=9

count2=9

b)        count1=10

count2=9

c)         count1=10

count2=10

d)        count1=9

count2=10


 

25.     Java, 以下(c )命令能够将Java源文件编译为类文件.   (选择一项)

a)         Java

b)        Javaw

c)         Javac

d)        Jar

 

26.     java中,下列()语句不能通过编译.(选择一项)

a)         String s =”john”+”was”+”here”;

b)        String s =”john”+3;

c)         int a =3+5;

d)        float f =5+5.5;

 

27.     给定java代码,如下:编译运行,结果是()。(选择一项)

public static void main(String[] args)

{

       String s;

       System.out.prinln(“s=”+s);

}

a)         编译错误

b)        编译通过,但出现运行时错误

c)         正常运行,输出s=null

d)        正常运行,输出s=

 

28.     Java语言中,下面变量命名合法的有()

a)         variable123

b)        123varable

c)         Private(private)

d)        -variable_123

 

29.     JAVA,()关键字用来终止循环语句。(选择一项)

a)         Return

b)        Continue

c)         Break

d)        Exit


 

 

30.     给定某Java程序的main方法如下,该程序的运行结果是()。(选择一项)

public static void main(String[] args){

boolean boo=true;

If(boo==false){

System.out.println(“a”);

}

else{

       Systim.out.println(“b”)

       }

}

a)         a

b)        b

c)         c

d)        d

 

31.     给定某Java程序的main方法如下,该程序的运行结果是()

public static void main(String[] args){

              boolean boo=false;

              if(boo=true){

              System.out.println("a");

              }

              else{

                     System.out.println("b");

                     }

       }

a)         a

b)        b

c)         c

d)        d

 

 

32.     研究下面的Java代码,x=2,运行结果是( )。(选择一项)

Switch(x){

       case 1:

              System.out.println(1);

       case 2:

       case 3:    

              System.out.println(3);

              System.out.println(4);

}

a)         没有任何输出结果

b)        输出结果为3

c)         输出结果为34

d)        输出结果是134

 

33.     Java 语言中有如下代码,下列x的定义中,可以使上段代码输出 100 的有 ( )

switch(x){

case 100:

System-out.println("100");break;

case 110:

System-out-println("110");break;

}

a)         String x=”100”;

b)        float x=100;

c)         char x='d';a=97 b=98 c=99 d=100

d)        long x=100;

 


 

34.     以下会产生编译错误的Java语句是()。

a)         if (2 == 3) System.out.println("Hi");

b)        if (2 = 3) System.out.println("Hi");

c)         if (true) System.out.println("Hi");

d)        if (2 != 3) System.out.println("Hi");

 

35.     给定java代码如下:要使用这段代码能够编译成功,横线处可以填入()

pubilc int count(char c,int i,double d){

       return______;

}

a)         c*i

b)        c*d

c)         (int)c*d

d)        i*d

 

36.     给定java代码片段,如下

int i=0,j=-1;

switch(i){

          case 0,1:j=1;

          case 2:j=2;

}

System.out.print("j="+j);

编译运行,正确的是()。

a)         程序编译出错

b)        j=1

c)         j=2

d)        j=0

 

37.     给定一个java程序的代码片断如下,编译执行后的输出结果是()

char c=’a’;

int i=c;

float f=i++;

byte b=(byte)(f+1);

System.out.println(c+”,”+i+”,”+f+”,”+b);

a)         a,97, 97.0 98;

b)        a ,97, 97, 98;

c)         a ,98 ,97.0,98;

d)        a, 98 , 97,98

 

38.     Java 中,byte数据类型的取值范围是 ()

a)         -256 255

b)        -255 255

c)         -128 127

d)        -127 128

39.     以下JAVA注释不正确的是()

a)         /*这是一//个注释*/

b)        /*这是一个注释*/

c)         /* 这是一*/一个注释*/

d)        // 这是一个注释//

 

40.     以下JAVA类声明正确的是()

a)         Class 1demo

…..

}

b)        Class demo{

……

}

c)         Demo class{

…..

}

d)        Class 123{

….

}

 

41.     main方法是java application程序执行的入口点,关于main方法头以下是合法()

a)         public stativ void mian()

b)        public static void main(String[] args)

c)         public static int main(String[] args)

d)        public void main(String args)

 

42.     在下面的语句中()正确声明并初始化float的变量

a)         float f;

b)        f  = 12;

c)         float f = 12f;

d)        float f ; f = 12f;

 

43.     已知:int x = 10,y = 4; x / y的值为()

a)         2

b)        2.0

c)         2.5

d)        0


 

44.     给定一个java程序的代码片断如下,编译执行后的输出结果是()

int num = 5;

int sum = num++;

System.out.println(“num=” + num);

System.out.println(“sum=” + sum);

a)         num = 5

sum = 5

b)        num = 6

sum = 5

c)         num = 6

sum = 6

d)        num = 6

sum = 5

 

45.     已知:int a = 5, b = 9, c = 5 下列表达式的值为false的是()

a & b;

a)         a && b && c;

b)        (a > b) && < (c++ < b)

c)         a || b + c&&c – b;

 

46.     public class Demo{

public static void main(String[] args){

       int x = 3;

       int y = 1;

       if(x = y){

              System.out.println(“No equal”);

       }else{

              System.out.println(“Equal”);

       }

}

}

以上程序执行结果是什么?

a)         程序编译出错

b)        Not equal

c)         Equal

d)        以上都不对


 

 

47.     以下程序片段

int  i = 1;

while(i < 5){/

       i++;

}

System.out.println(i);

运行后()

a)         输出1

b)        输出5

c)         程序无法运行

d)        死循环

 

48.     下列程序

public class Demo{

       public static void main(String[] args){

              int i = 0;

                     for(i = 10;i<10;i++){

                            System.out.println(i);

                     }

                     System.out.println(i);

       }

}

程序的输出为:

a)         0

b)        10

c)         11

d)        程序编译错误


 

49.     下面的代码段

       switch(c){

       case 'a':

              System.out.println("a");

       case 'b':

              System.out.println("b");

       case ‘c’:

       case ‘d’:

              System.out.println(“d”);

       }    

       c的值为b的时候程序会输出( )

a)         b

b)        a

b

c

c)         b

d

d)        d

 

50.     下面对于方法的描述,正确的有( )

a)         方法必须返回一个值

b)        方法可以返回多个值

c)         在方法内可以定义其他方法

d)        方法可以有多个参数


 

 

51.     阅读以下的代码,运行后结果输出( )

public class Demo{

       public static void main(String[] args){

              String str = new String(“good”);

              char[] ch = {‘a’,’b’,’c’};

              change(str,ch);

              System.out.print(str + “and ”);

              System.out.print(ch);

       }

 

Public static void change(String str,char ch[]){

       Str = “test ok”;

       ch[0] = ‘g’;

}

}

a)         good and abc

b)        good and gbc

c)         test ok and abc

d)        test ok and gbc

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值