收藏 分销(赏)

Java练习题1(有答案).pdf

上传人:精**** 文档编号:2048294 上传时间:2024-05-14 格式:PDF 页数:53 大小:171.05KB
下载 相关 举报
Java练习题1(有答案).pdf_第1页
第1页 / 共53页
Java练习题1(有答案).pdf_第2页
第2页 / 共53页
Java练习题1(有答案).pdf_第3页
第3页 / 共53页
Java练习题1(有答案).pdf_第4页
第4页 / 共53页
Java练习题1(有答案).pdf_第5页
第5页 / 共53页
点击查看更多>>
资源描述

1、第 1 题 _ is an object-oriented programming language.1、Java 2、C+3、C 4、Ada 5、Pascal 答案 1 2 第 2 题 _ is Architecture-Neutral.1、Java 2、C+3、C 4、Ada 5、Pascal 答案 1 第 3 题 _ is a technical definition of the language that includes the syntax and semantics of the Java programming language.1、Java language specifi

2、cation 2、Java API 3、Java JDK 4、Java IDE 答案 1 第 4 题 _ consists of a set of separate programs for developing and testing Java programs,each of which is invoked from a command line.1、Java language specification 2、Java API 3、Java JDK 4、Java IDE 答案 3 第 5 题 _ provides an integrated development environment

3、(IDE)for rapidly developing Java programs.Editing,compiling,building,debugging,and online help are integrated in one graphical user interface.1、Java language specification 2、Java API 3、Java JDK 4、Java IDE 答案 4 第 6 题 The main method header is written as:1、public static void main(string args)2、public

4、static void Main(String args)3、public static void main(String args)4、public static main(String args)5、public void main(String args)答案 3 第 7 题 Which of the following statements is correct?1、Every line in a program must end with a semicolon.2、Every statement in a program must end with a semicolon.3、Ev

5、ery comment line must end with a semicolon;4、Every method must end with a semicolon;5、Every class must end with a semicolon;答案 2 第 8 题 Which of the following statements is correct to display Welcome to Java on the console?1、Welcome to Java);2、Welcome to Java);3、System.println(Welcome to Java);4、Welc

6、ome to Java);5、Welcome to Java);答案 2 5 第 9 题 Which JDK command is correct to run a Java application in ByteCode.class?1、java ByteCode 2、java ByteCode.class 3、javac ByteCode.java 4、javac ByteCode 5、JAVAC ByteCode 答案 1 第 10 题 Suppose you define a Java class as follows:public class Test In order to com

7、pile this program,the source code should be stored in a file named 1、Test.class 2、Test.doc 33、Test.txt 4、Test.java 5、Any name with extension.java 答案 4 第 11 题 The extension name of a Java bytecode file is 1、.java 2、.obj 3、.class 4、.exe 答案 3 第 12 题 Which of the following lines is not a Java comment?1、

8、/*comments*/2、/comments 3、-comments 4、/*comments*/5、*comments*答案 3 5 第 13 题 Which of the following are the reserved words?1、public 2、static 3、void 4、class 答案 1 2 3 4 第 14 题 To use JOptionPane in your program,you may import it using:1、import;2、import javax.swing.*;3、import javax.*;4、import javax.*.JO

9、ptionPane;答案 1 2 第 15 题 Which of the following are correct names for variables according to Java naming conventions?1、radius 2、Radius 3、RADIUS 4、findArea 5、FindArea 答案 1 4 第 16 题 Which of the following are correct ways to declare variables?1、int length;int width;2、int length,width;3、int length;width

10、;4、int length,int width;答案 1 2 第 17 题 _ is the Java assignment operator.1、=2、:=3、=4、=:答案 3 第 18 题 Which of the following assignment statements is incorrect.1、i=j=k=1;2、i=1;j=1;k=1;3、i=1=j=1=k=1;4、i=j=k=1;答案 3 4 第 19 题 Which of the following is a constant,according to Java naming conventions?1、MAX_VA

11、LUE 2、Test 3、read 4、ReadInt 5、COUNT 答案 1 5 第 20 题 To declare an int variable number with initial value 2,you write 1、int number=2L;2、int number=2l;3、int number=2;4、int number=2.0;答案 3 第 21 题 Which of the following expressions will yield 0.5?1、1/2 2、1.0/2 3、(double)(1/2)4、(double)1/2 5、1/2.0 答案 2 4 5

12、 第 22 题 Which of the following expression results in a value 1?1、2%1 2、15%4 3、25%5 4、37%6 答案 4 第 23 题 -25%5 is _ 1、1 2、2 3、3 4、4 5、0 答案 5 第 24题 -24%-5 is _ 1、3 2、-3 3、4 54、-4 5、0 答案 4 第 25 题 To add number to sum,you write(Note:Java is case-sensitive)1、number+=sum;2、number=sum+number;3、sum=Number+sum

13、;4、sum+=number;5、sum=sum+number;答案 4 5 第 26 题 Suppose x is 1.What is x after x-=1?1、0 2、1 3、2 4、-1 5、-2 答案 1 第 27 题 What is x after the following statements?int x=1;int y=2;x*=y+1;1、x is 1;2、x is 2;3、x is 3;4、x is 4;答案 3 第 28 题 What is y displayed?public class Test public static void main(String arg

14、s)int x=1;int y=x+x+;y is +y);1、y is 1.2、y is 2.3、y is 3.4、y is 4.答案 2 第 29 题 What is y displayed in the following code?public class Test public static void main(String args)int x=1;int y=x+x;y is +y);1、y is 1.2、y is 2.3、y is 3.4、y is 4.答案 3 第 30 题 What is the printout of the following code:double x

15、=5.5;int y=(int)x;x is +x+and y is +y);71、x is 5 and y is 6 2、x is 6.0 and y is 6.0 3、x is 6 and y is 6 4、x is 5.5 and y is 5 5、x is 5.5 and y is 5.0 答案 4 第 31 题 Suppose x is a char variable with a value b.What is the printout of the statement 1、a 2、b 3、c 4、d 答案 3 第 32 题 Suppose i is an int type var

16、iable.Which of the following statements display the character whose Unicode is stored in variable i?1、;2、;3、;4、+);答案 2 第 33 题 The following code fragment reads in two numbers:Scanner input=new Scanner(System.in);int i=input.nextInt();double d=input.nextDouble();What are the correct ways to enter the

17、se two numbers?1、Enter an integer,a space,a double value,and then the Enter key.2、Enter an integer,two spaces,a double value,and then the Enter key.3、Enter an integer,an Enter key,a double value,and then the Enter key.4、Enter a numeric value with a decimal point,a space,an integer,and then the Enter

18、 key.答案 1 2 3 第 34 题 If you enter 1 2 3,when you run this program,what will be the output?import;public class Test1 public static void main(String args)Scanner input=new Scanner(System.in);Enter three numbers:);double number1=input.nextDouble();double number2=input.nextDouble();double number3=input.

19、nextDouble();/Compute average double average=(number1+number2+number3)/3;/Display result;1、1.0 2、2.0 3、3.0 4、4.0 答案 2 第 35 题 The expression(int)(76.0252175*100)/100 evaluates to _.1、76.02 2、76 3、76.0252175 4、76.03 答案 2 第 36 题 According to Java naming convention,which of the following names can be va

20、riables?1、FindArea 2、findArea 3、totalLength 4、TOTAL_LENGTH 5、class 答案 2 3 第 37 题 The _ method displays an input dialog for reading a string.1、String string=JOptionPane.showMessageDialog(null,Enter a string,Input Demo,JOptionPane.QUESTION_MESSAGE);2、String string=JOptionPane.showInputDialog(null,Ente

21、r a string,Input Demo,JOptionPane.QUESTION_MESSAGE);3、String string=JOptionPane.showInputDialog(Enter a string,Input Demo,JOptionPane.QUESTION_MESSAGE);4、String string=JOptionPane.showInputDialog(null,Enter a string);5、String string=JOptionPane.showInputDialog(Enter a string);答案 2 4 5 第 38 题 Analyze

22、 the following code.import javax.swing.*;public class ShowErrors public static void main(String args)int i;int j;String s=JOptionPane.showInputDialog(null,Enter an integer,Input,JOptionPane.QUESTION_MESSAGE);j=Integer.parseInt(s);i=(i+4);1、The program cannot compile because j is not initialized.2、Th

23、e program cannot compile because i does not have an initial value when it is used in i=i+4;3、The program compiles but has a runtime error because i does not have an initial value when it is used in i=i+4;4、The program compiles and runs fine.答案 2 第 39 题 Suppose x=10 and y=10.What is x after evaluatin

24、g the expression(y 10)&(x-10)?1、9 2、10 3、11 答案 2 第 40 题 Suppose x=10 and y=10 what is x after evaluating the expression(y=10)|(x+10).1、9 2、10 3、11 答案 2 第 41 题 Suppose x=1,y=-1,and z=1.What is the printout of the following statement?(Please indent the statement correctly first.)if(x 0)if(y 0)x 0 and

25、y 0);else if(z 0)x 0);1、x 0 and y 0;2、x 0;3、x 0 and z=100)too hot);else if(temperature 0&x 0)&(x 0|x 0)|(x 0|x 10&y 0|(x 10&y 0|x 10&y 0|x 10)&y 0)答案 1 2 3 第 54 题 How many times will the following code print Welcome to Java?int count=0;while(count 10)Welcome to Java);count+;1、8 2、9 3、10 4、11 5、0 答案

26、3 第 55 题 Analyze the following code.int count=0;while(count 100)/Point A Welcome to Java!);count+;/Point B /Point C 1、count 100 is always true at Point A 2、count 100 is always true at Point B 3、count 100 is always false at Point B 4、count 100 is always true at Point C 5、count 100 is always false at

27、Point C 答案 1 5 第 56 题 How many times will the following code print Welcome to Java?int count=0;do Welcome to Java);while(count+10);1、8 2、9 3、10 4、11 5、0 答案 4 第 57 题 What is the value in count after the following loop is executed?int count=0;do Welcome to Java);while(count+9);1、8 2、9 3、10 4、11 5、0 答案

28、 3 第 58 题 Do the following two statements in(I)and(II)result in the same value in sum?(I):for(int i=0;i10;+i)sum+=i;(II):for(int i=0;i10;i+)sum+=i;1、Yes 2、No 答案 1 第 59 题 Is the following loop correct?for(;);1、Yes 2、No 答案 1 第 60 题 Analyze the following code:public class Test public static void main(S

29、tring args)int i=0;for(i=0;i 10;i+);+4);1、The program has a compile error because of the semicolon(;)on the for loop line.2、The program compiles despite the semicolon(;)on the for loop line,and displays 4.3、The program compiles despite the semicolon(;)on the for loop line,and displays 14.4、The for l

30、oop in this program is same as for(i=0;i 4)break;while(item 5);1、5 2、6 3、7 4、8 答案 2 第 63 题 After the continue outer statement is executed in the following loop,which statement is executed?outer:for(int i=1;i 10;i+)inner:for(int j=1;j 50)continue outer;*j);next:1、The control is in the outer loop,and

31、the next iteration of the outer loop is executed.2、The control is in the inner loop,and the next iteration of the inner loop is executed.3、The statement labeled next.4、The program terminates.答案 1 第 64 题 Suppose the input for number is 9.What is the output from running the following program?import;pu

32、blic class Test public static void main(String args)Scanner input=new Scanner(System.in);Enter an integer:);int number=input.nextInt();int i;boolean isPrime=true;for(i=2;i 0);n-;What is the printout of the call nPrint(a,4)?1、aaaaa 2、aaaa 3、aaa 4、invalid call 答案 4 第 70 题 Suppose static void nPrint(St

33、ring message,int n)while(n 0);n-;What is k after invoking nPrint(A message,k)?int k=2;nPrint(A message,k);1、0 2、1 3、2 4、3 答案 3 第 71 题 Analyze the following code:public class Test public static void main(String args),500L);public static int xMethod(int n,long l)int,long);return n;public static long x

34、Method(long n,long l)long,long);return n;1、The program displays int,long followed by 5.2、The program displays long,long followed by 5.3、The program runs fine but displays things other than 5.4、The program does not compile because the compiler cannot distinguish which xmethod to invoke.答案 1 第 72 题 An

35、alyze the following code.public class Test public static void main(String args),2);public static double max(int num1,double num2)max(int,double)is invoked);if(num1 num2)return num1;else return num2;public static double max(double num1,int num2)max(double,int)is invoked);if(num1 num2)return num1;else

36、 return num2;1、The program cannot compile because you cannot have the print statement in a non-void method.2、The program cannot compile because the compiler cannot determine which max method should be invoked.3、The program runs and prints 2 followed by max(int,double)is invoked.4、The program runs an

37、d prints 2 followed by max(double,int)is invoked.5、The program runs and prints max(int,double)is invoked followed by 2.答案 2 第 73 题 The client can use a method without knowing how it is implemented.The details of the implementation are encapsulated in the 19method and hidden from the client who invok

38、es the method.This is known as _.1、information hiding 2、encapsulation 3、method hiding 4、simplifying method 答案 1 2 第 74 题 What is Math.floor(3.6)?1、3.0 2、3 3、4 4、5.0 答案 1 第 75 题 If you declare an array double list=3.4,2.0,3.5,5.5,list1 is _.1、3.4 2、2.0 3、3.4 4、5.5 5、undefined 答案 2 第 76 题 If you decla

39、re an array double list=3.4,2.0,3.5,5.5,the highest index in array list is _.e,4 1、0 2、1 3、2 4、3 答案 4 第 77 题 Suppose int i=5,which of the following can be used as an index for array double t=new double100?1、i 2、(int)(Math.random()*100)3、i+10 4、i+6.5 5、Math.random()*100 答案 1 2 3 第 78 题 Analyze the fo

40、llowing code.public class Test public static void main(String args)int x=new int3;x0 is +x0);1、The program has a compile error because the size of the array wasn t specified when declaring the array.2、The program has a runtime error because the array elements are not initialized.3、The program runs f

41、ine and displays x0 is 0.4、The program has a runtime error because the array element x0 is not defined.答案 3 第 79 题 What would be the result of attempting to compile and run the following code?public class Test public static void main(String args)double x=new double1,2,3;Value is +x1);1、The program h

42、as a compile error because the syntax new double1,2,3 is wrong and it should be replaced by 1,2,3.2、The program has a compile error because the syntax new double1,2,3 is wrong and it should be replaced by new double31,2,3;3、The program has a compile error because the syntax new double1,2,3 is wrong

43、and it should be replaced by new double1.0,2.0,3.0;4、The program compiles and runs fine and the output Value is 1.0 is printed.5、The program compiles and runs fine and the output Value is 2.0 is printed.答案 5 第 80 题 Analyze the following code:public class Test public static void main(String args)int

44、x=new int5;int i;for(i=0;i x.length;i+)xi=i;1、The program displays 0 1 2 3 4.2、The program displays 4.3、The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException.4、The program has a compile error because i is not defined in the last statement

45、 in the main method.答案 3 第 81 题 In the following code,what is the printout for list2?class Test public static void main(String args)int list1=1,212,3;int list2=1,2,3;list2=list1;list10=0;list11=1;list22=2;for(int i=0;i list2.length;i+)+);1、1 2 3 2、1 1 1 3、0 1 2 4、0 1 3 答案 3 第 82 题 In the following c

46、ode,what is the printout for list1?class Test public static void main(String args)int list1=1,2,3;int list2=1,2,3;list2=list1;list10=0;list11=1;list22=2;for(int i=0;i list1.length;i+)+);1、1 2 3 2、1 1 1 3、0 1 2 4、0 1 3 答案 3 第 83 题 Analyze the following code:public class Test public static void main(S

47、tring args)int x=1,2,3,4;int y=x;x=new int2;for(int i=0;i x.length;i+)+);1、The program displays 1 2 3 4 2、The program displays 0 0 3、The program displays 0 0 3 4 4、The program displays 0 0 0 0 答案 2 第 84 题 Analyze the following code:public class Test public static void main(String args)final int x=1,

48、2,3,4;int y=x;x=new int2;for(int i=0;i y.length;i+)+);1、The program displays 1 2 3 4 2、The program displays 0 0 3、The program has a compile error on the statement x=new int2,because x is final and cannot be changed.4、The elements in the array x cannot be changed,because x is final.答案 3 第 85 题 Analyz

49、e the following code:public class Test public static void main(String args)int a=new int4;a1=1;a=new int2;a1 is +a1);1、The program has a compile error because new int2 is assigned to a.2、The program has a runtime error because a1 is not initialized.3、The program displays a1 is 0.4、The program displa

50、ys a1 is 1.答案 3 第 86 题 Show the output of the following code:public class Test public static void main(String args)int x=1,2,3,4,5;increase(x);int y=1,2,3,4,5;increase(y0);+y0);public static void increase(int x)for(int i=0;i x.length;i+)xi+;public static void increase(int y)y+;1、0 0 2、1 1 3、2 2 4、2

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
百度文库年卡

猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服