《java练习题2.pdf》由会员分享,可在线阅读,更多相关《java练习题2.pdf(94页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、 第1 题 is an object-oriented programming language.1、Java2、C+3、C4、Ada5、Pascal第2题 is Architecture-Neutral.1、Java2、C+3、C4、Ada5、Pascal第3题 is a technical definition of the language that includes thesyntax and semantics of the Java programming language.1、Java language specification2、Java API3、Java JDK4、Jav
2、a IDE第4题 consists of a set of separate programs for developing andtesting Java programs,each of which is invoked from a command line.1、Java language specification2、Java API3、Java JDK4、Java IDE第5题 provides an integrated development environment(IDE)forrapidly developing Java programs.Editing,compiling
3、,building,debugging,and online help are integrated in one graphical user interface.1、Java language specification2、Java API3、Java JDK4、Java IDE第6题The main method header is written as:1、public static void main(string args)2、public static void Main(StringO args)3、public static void main(StringQ args)4、
4、public static main(String args)5、public void main(StringO args)第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、Every comment line must end with a semicolon;4、Every method must end with a se
5、micolon;5、Every class must end with a semicolon;第8题Which of the following statements is correct to display Welcome toJava on the console?1、System.out.println(Welcome to Java);2、System.out.println(Welcome to Java);3、System.println(Welcome to Java);4 System.out.print(Welcome to Java);5、System.out.prin
6、t(Welcome to Java1);第9题Which JDK command is correct to run a Java application inByteCode.class?1、java ByteCode2、java ByteCode.class3、javac ByteCode.java4、javac ByteCode5、JAVAC ByteCode第 10题Suppose you define a Java class as follows:public class Test)In order to compile this program,the source code s
7、hould be stored in a filenamed1、Test.class2、Test.doc3、Test.txt4、Test.java5、Any name with extension.java第11 题The extension name of a Java bytecode file is1、.java2v.obj3、.class4、.exe第 12题Which of the following lines is not a Java comment?1、/*comments*/2、/comments3、-comments4、/*comments*/5、*comments*第
8、13题Which of the following are the reserved words?1、public2、static3、void4、class第14题To use JOptionPane in your program,you may import it using:1、import javax.swing.JOptionPane;2、import javax.swing.*;3、import javax.*;4、import javax.*.JOptionPane;第 15题Which of the following are correct names for variabl
9、es according toJava naming conventions?1、radius2、Radius3、RADIUS4、find Area5、FindArea第 16题Which of the following are correct ways to declare variables?1、int length;int width;int length,width;int length;width;4%int length,int width;第17题 is the Java assignment operator.1、=2、:=3、=4、=:第 18题Which of the f
10、ollowing assignment statements is incorrect.j=j=k=1;2.i=1;j=1;k=1;3、i=1 =j=1 =k=1;4v j=j=k=1;第 19题Which of the following is a constant,according to Java namingconventions?1、MAX_VALUE2、Test3、read4、Read I nt5、COUNT第20题To declare an int variable number with initial value 2,you write1、int number=2L;2、in
11、t number=2I;3、int number=2;4%int number=2.0;第21 题Which of the following expressions will yield 0.5?1、1 122、1.0/23、(double)(1/2)4、(double)1125、1/2.0第22题Which of the following expression results in a value 1?1、2%12、15%4 3、25%54、37%6第23题25%5 is1、12、23、34、45、0第24题-24%-5 is1、32、33、44、-45、0第25题To add numb
12、er to sum,you write(Note:Java is case-sensitive)1、number+=sum;2、number=sum+number;3、sum=Number+sum;4、sum+=number;5、sum=sum+number;第26题Suppose x is 1.What is x after x-=1?1、02、13、24、5、-2第27题What is x after the following statements?intx=1;int y=2;x*=y+1;1s x is 1;2、xis 2;3、x is 3;4、x is 4;第28题What is
13、y displayed?public class Testpublic static void main(StringO args)int x=1;int y=x+x+;System.out.println(y is +y);)1、y is 1.2、yis 2.3、y is 3.4、y is 4.第29题What is y displayed in the following code?public class Testpublic static void main(StringO args)int x=1;int y=x+x;System.out.println(y is*+y);)1、y
14、is 1.2、y is 2.3、y is 3.4、y is 4.第30题What is the printout of the following code:double x=5.5;int y=(int)x;System.out.println(x isM+x+M and y is+y);1、x is 5 and y is 62、x is 6.0 and y is 6.03、x is 6 and y is 64、x is 5.5 and y is 55、x is 5.5 and y is 5.0第31 题Suppose x is a char variable with a value b.
15、What is the printout ofthe statement System.out.println(+x)?1、a2、b3、c4、d第32题Suppose i is an int type variable.Which of the following statementsdisplay the character whose Unicode is stored in variable i?1、System.out.println(i);2、System.out.println(char)i);3 System.out.println(int)i);4、System.out.pri
16、ntln(i+第33题The following code fragment reads in two numbers:Scanner input=new Scanner(System.in);int i=input.nextlnt();double d=input.nextDouble();What are the correct ways to enter these two numbers?1、Enter an integer,a space,a double value,and then the Enter key.2、Enter an integer,two spaces,a dou
17、ble 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 thenthe Enter key.第34题If you enter 1 2 3,when you run this program,what will be theoutput?import java.util.Scanner;public class T
18、esti public static void main(StringO args)Scanner input=new Scanner(System.in);System.out.print(Enter three numbers:);double numberl=input.nextDouble();double number2=input.nextDouble();double numbers=input.nextDoubleQ;/Compute averagedouble average=(numberl+number2+number3)/3;/Display resultSystem.
19、out.println(average);)1、1.02、2.03、3.04、4.0第35题The expression(int)(76.0252175*100)/100 evaluates to1、76.022、763、76.02521754、76.03第36题According to Java naming convention,which of the following namescan be variables?1、FindArea2、find Area3、totalLength4、TOTAL.LENGTH5、class第37题The method displays an input
20、 dialog for reading astring.1、String string=JOptionPane.showMessageDialog(null,Enter a string1,Input Demo,JOptionPane.QUESTION_MESSAGE);2、String string=JOptionPane.showlnputDialog(null,MEnter a string,Input Demo”,JOptionPane.QUESTION_MESSAGE);3、String string=JOptionPane.showlnputDialog(Enter a strin
21、g,InputDemo,JOptionPane.QUESTION_MESSAGE);4 String string=JOptionPane.showlnputDialog(null,Enter a string);5、String string=JOptionPane.showInputDialogfEnter a string);第38题Analyze the following code.import javax.swing.*;public class ShowErrors public static void main(StringO args)int i;intj;String s=
22、JOptionPane.showlnputDialog(null,Enter an integer,Input,JOptionPane.QUESTION_MESSAGE);j=Integer.parselnt(s);i=(i+4);)1、The program cannot compile because j is not initialized.2、The program cannot compile because i does not have an initial valuewhen it is used in i=i+4;3、The program compiles but has
23、a runtime error because i does not have aninitial value when it is used in i=i+4;4、The program compiles and runs fine.第39题Suppose x=10 and y=10.What is x after evaluating the expression(y10)&(x-10)?1、92、103、11第40题Suppose x=10 and y=10 what is x after evaluating the expression(y=10)|(x+10).1、92、103、1
24、1第41 题Suppose x=1,y=-1,and z=1.What is the printout of thefollowing statement?(Please indent the statement correctly first.)if(x 0)if(y 0)System.out.println(x 0 and y 0n);else if(z 0)System.out.println(x 0);1s x 0 and y 0;2、x v 0 and z 0;3s x 0 and z=100)System.out.println(too hot);else if(temperatu
25、re 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)第54题How many times will the following code print Welcome to Java?int count=0;while(count 10)System.out.println(MWelcome to Java);count+;)1、82、93、104、115、0第55题Analyze the following code.int count=0;while(count 100)/Point ASystem.out.print
26、ln(Welcome to Java!1);count+;/Point B)/Point C1、count 100 is always true at Point A2、count 100 is always true at Point B3、count 100 is always false at Point B4、count 100 is always true at Point C5、count 100 is always false at Point C第56题How many times will the following code print Welcome to Java1?i
27、nt count=0;doSystem.out.println(Welcome to Java);while(count+10);1、82、93、104、115、0第57题What is the value in count after the following loop is executed?int count=0;do System.out.println(MWelcome to Java);while(x)unt+9);System.out.println(count);1、82、93、104、115、0 第58题Do the following two statements in(
28、I)and(II)result in the samevalue in sum?(I):for(int i=0;i10;+j)sum+=i;)(II):for(int i=0;i10;i+)sum+=i;)1、Yes2、No第59题Is the following loop correct?for(;);1、Yes2、No第60题Analyze the following code:public class Testpublic static void main(String argsO)int i=0;for(i=0;i 10;i+);System.out.println(i+4);)1、T
29、he program has a compile error because of the semicolon(;)on the forloop line.2、The program compiles despite the semicolon(;)on the for loop line,anddisplays 4.3、The program compiles despite the semicolon(;)on the for loop line,anddisplays 14.4、The for loop in this program is same as for(i=0;i 4)bre
30、ak;)while(item 5);1、52、63、74、8第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;System.out.println(i*j);)next:1、The control is in the outer loop,and the next iteration of the outer loop
31、 isexecuted.2、The control is in the inner loop,and the next iteration of the inner loop isexecuted.3、The statement labeled next.4、The program terminates.第64题Suppose the input for number is 9.What is the output from runningthe following program?import java.util.Scanner;public class Test public static
32、 void main(StringO args)Scanner input=new Scanner(System.in);System.out.print(HEnter an integer:);int number=input.nextlnt();int i;boolean isPrime=true;for(i=2;i 0)System.out.print(message);n-;)What is the printout of the call nPrint(a,4)?1、aaaaa2、aaaa3、aaa4X invalid call第 70 题 Supposestatic void nP
33、rint(String message,int n)while(n 0)System.out.print(message);n-;)What is k after invoking nPrint(A message,k)?int k=2;nPrint(A message,k);1、02、13、24、3第71 题Analyze the following code:public class Testpublic static void main(StringQ args)System.out.println(xMethod(5,500L);)public static int xMethod(i
34、nt n,long I)System.out.println(int,long1);return n;)public static long xMethod(long n,long I)System.out.printlnClong,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 doe
35、s not compile because the compiler cannot distinguishwhich xmethod to invoke.第72题Analyze the following code.public class Testpublic static void main(String args)System.out.println(max(1,2);)public static double max(int num1,double num2)System.out.println(max(int,double)is invoked);if(num1 num2)retur
36、n num1;elsereturn num2;)public static double max(double num1,int num2)System.out.println(nmax(double,int)is invoked*);if(num1 num2)return num1;elsereturn num2;)1、The program cannot compile because you cannot have the printstatement in a non-void method.2、The program cannot compile because the compil
37、er cannot determinewhich max method should be invoked.3、The program runs and prints 2 followed by max(int,double)is invoked.4、The program runs and prints 2 followed by max(double,int)*is invoked.5、The program runs and prints max(int,double)is invoked followed by 2.第73题The client can use a method wit
38、hout knowing how it is implemented.The details of the implementation are encapsulated in the method andhidden from the client who invokes the method.This is known as1、information hiding2、encapsulation3、method hiding4、simplifying method第74题What is Math.floor(3.6)?1、3.02、33、44、5.0第75题If you declare an
39、 array doubleQ list=3.4,2.0,3.5,5.5,list1 is1、3.42、2.03、3.44、5.55、undefined 第76题If you declare an array doubleO list=3.4,2.0,3.5,5.5,thehighest index in array list is.e,41、02、13、24、3第77题Suppose int i=5,which of the following can be used as an index forarray doubleO t=new double100?1、i2、(int)(Math.ra
40、ndom()*100)3、i+104、i+6.55、Math.random()*100第78题Analyze the following code.public class Test public static void main(String args)intQ x=new int3;System.out.println(x0 is+x0);)1、The program has a compile error because the size of the array wasn tspecified when declaring the array.2、The program has a r
41、untime error because the array elements are notinitialized.3、The program runs fine and displays x0 is 0.4、The program has a runtime error because the array element x0 is notdefined.第79题What would be the result of attempting to compile and run thefollowing code?public class Test public static void ma
42、in(String args)doubleO x=new double口1,2,3;System.out.printlnfValue is+x1);)1、The program has a compile error because the syntax new double01,2,3 is wrong and it should be replaced by 1,2,3).2、The program has a compile error because the syntax new double口1,2,3 is wrong and it should be replaced by ne
43、w double31,2,3;3、The program has a compile error because the syntax new double口1,2,3 is wrong and it should be replaced by new doubleQ1.0,2.0,3.0;4、The program compiles and runs fine and the output Value is 1.0*isprinted.5、The program compiles and runs fine and the output Value is 2.0*isprinted.第80题
44、Analyze the following code:public class Test public static void main(String args)into x=new int5;inti;for(i=0;i x.length;i+)xi=i;System.out.println(xi);)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 mainmethod causes Arr
45、aylndexOutOfBoundsException.4、The program has a compile error because i is not defined in the laststatement in the main method.第81 题In the following code,what is the printout for Iist2?class Test public static void main(StringO args)into listl=1,2,3;into Iist2=1,2,3);Iist2=listl;listl 0=0;listl 1=1;
46、Iist22=2;for(int i=0;i Iist2.length;i+)System.out.print(list2i+);)1、1232.1 1 13、01 24、01 3第82题In the following code,what is the printout for listl?class Test public static void main(StringO args)intQ listl=1,2,3;intQ Iist2=1,2,3;Iist2=listl;listl 0=0;listl 1=1;Iist22=2;for(int i=0;i listl.length;i+)
47、System.out.print(list1 i+);)1.1 2 32.1 1 13、01 24、01 3第83题Analyze the following code:public class Test public static void main(StringO args)intQx=1,2,3,4);int y=x;x=new int2;for(int i=0;i x.length;i+)System.out.print(xi+”);)1、The program displays 12 342、The program displays 0 03、The program displays
48、 0 0 3 44、The program displays 0 0 0 0第84题Analyze the following code:public class Testpublic static void main(StringO args)final intQ x=1,2,3,4;into y=x;x=new int2;for(int i=0;i y.length;i+)System.out.print(yi+);)1、The program displays 12 342、The program displays 0 03、The program has a compile error
49、 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.第85题Analyze the following code:public class Testpublic static void main(String args)intQ a=new int4;a1=1;a=new int2;System.out.println(a1 is +a1);)1、The program ha
50、s 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 displays a1 is 1.第86题Show the output of the following code:public class Test public static void main(StringO args)intQx=1,2,3,4,5;increase(