Java練習(xí)題1有答案_第1頁
Java練習(xí)題1有答案_第2頁
Java練習(xí)題1有答案_第3頁
Java練習(xí)題1有答案_第4頁
Java練習(xí)題1有答案_第5頁
已閱讀5頁,還剩49頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、第1題 is an object-oriented programming language.1、Java2、C+3、C4、Ada5、Pascal答案1 2第2題 is Architecture-Neutral.1、Java2、C+3、C4、Ada5、Pascal答案 1第3題 _ is a technical definition of the language that includesthe syntax and semantics of the Java programming language.1、Java language specification2、Java API3、Java

2、 JDK4 、 Java IDE答案 1第4 題 consists of a set of separate programs for developingand testing Java programs, each of which is invoked from a command line.1 、 Java language specification2 、 Java API3 、 Java JDK4 、 Java IDE答案 3第 5 題 provides an integrated development environment (IDE)for rapidly developin

3、g Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface.1 、 Java language specification2 、 Java API答案 4 第 6 題The main method header is written as: 1 、 public static void main(string args)3 、 Java JDK 4Java IDE2 、 public static void Mai

4、n(String args)3 、 public static void main(String args)4 、 public static main(Stringargs) 5 、 publicvoid main(String args)答案 3 第 7 題 Which ofthe following statements is correct?1 、 Every linein a program must end with a semicolon.2 、 Every statement in a program must end with a semicolon.3 、 Every co

5、mment 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 )

6、;4 、 Welcome to Java );5 、 Welcome to Java); 答案 2 5第 9 題 Which JDK command is correct to run a Java application in ByteCode.class?1 、 java ByteCode2 、 java ByteCode.class3 、 javac ByteCode.java4 、 javac ByteCode 5 、 JAVAC ByteCode 答案 1第 10 題 Suppose you define a Java class as follows: public class T

7、est In order to compile this program, the source code should be stored in a file named1 、 Test.class2 、 Test.doc3 、 Test.txt答案 4 第 11 題4 、 Test.java5 、 Any name with extension .java第 16 題 Which oftheThe extension name of a Java bytecode file is1、.java2、.obj3、.class4、.exe 答案 3 第 12 題Which of the foll

8、owing lines isnot a Java comment?1、/* comments */2、/ comments3、- comments4、/* comments */5、* comments * 答案3 5 第 13 題 Which of thefollowing are the reserved words?1、public2、static3、void 4 、 class 答案 12 3 4 第 14 題 To use JOptionPane inyour program, you may import it using1、import ;2、import javax.swing

9、.*;3、import javax.*;4、import javax.*.JOptionPane;答案1 2第15 題 Which of the following are correct names for variables accordingto Java naming conventions?1、radius2、Radius3、RADIUSfindArea4、答案 1 45 、 FindAreafollowing are correct ways to declare variables?1、int length; int width;2、int length, width;3、int

10、 length; width; 4int length, int width;答案 1第 17 題is the Javaassignment9operator.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,

11、according to Java namingconventions? 1 、 MAX_VALUE2 、 Test3 、 read4 、 ReadInt 5 、 COUNT 答案 1 5 第 20 題 To declare an int variable number with initial value 2, you write1 、 int number = 2L;2 、 int number = 2l;3 、 int number = 2; 4 、 int number = 2.0; 答案 3 第21 題 Which of the following expressions will

12、yield 0.5?1、1 / 22 、 1.0 / 23 、 (double) (1 / 2)4 、 (double) 1 / 2 5、 1 / 2.0 答案 2 4 5 第 22 題 Whichof the following expression results in a value 1?1、2 % 12 、 15 % 43 、 25 % 5 4 、 37 % 6 答案 4 第 23 題 -25 % 5 is 1 、 12 、 23 、 34 、 4 5 、 0 答案 5 第 24題 -24 % -5 is 1 、 32 、 -34 、 -4 5 、 0 答案 4 第 25 題 To a

13、dd number 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; 案4 5第 26 題 Suppose x is 1. What is x after x -= 1?1、02、13、24、-1 5 、 -2 答案 1第 27 題 What is x afterthe following statements?int x = 1;

14、int y = 2; x*= y + 1;1、x is1;2、x is 2;3、x is 3;4 、x is 4;答案3第28 題Whatis ydisplayed?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. 答案 2 第 29 題 What is y displayed in the following code?public class Test public static voi

15、d 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 isthe printout of the following code: double x = 5.5;int y = (int)x;x is + x + 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 6Suppose x4、x is 5.5 and y is 5 5、

16、 x is 5.5 and y is 5.0答案 4 第 31 題is a char variable with a value b . What is the printout of the statement 1、 2、3、答案 3 第 32 題 Suppose i is an int type variable. Which ofthefollowingstatementsdisplay the character whoseUnicodeis storedin variable i?1、2、 this program, what will be the output?3、 );答案2

17、第 33 題 The following codefragmentreadsintwonumbers:ScannerinputnewScanner(System.in);inti = input.nextInt();doubleinput.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 double value

18、, 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, andthen the Enter key.答案 1 2 3第 34 題 If you enter 1 2 3, when you runimport ; public class Test1 public static void main(String args) S

19、canner input = new Scanner(System.in); Enter three numbers: ); double number1 = input.nextDouble(); double number2 = input.nextDouble(); double number3 = input.nextDouble();/ Compute average double average = (number1 + number2 + number3) / 3; / Display result1、1.02、2.03、3.04 、 4.0 答案 2 第 35 題 The ex

20、pression (int)(76.0252175 * 100)/ 100 evaluates to .1 、 76.022 、 763 、 76.0252175 4 、 76.03 答案 2 第 36 題 According to Java naming convention, which of the following names can be variables?1 、 FindArea2 、 findArea3 、 totalLength4 、 TOTAL_LENGTH5 、 class 答案 2 3 第 37 題 The method displays an inputdialog

21、 for reading a string.1 、 String string = JOptionPane.showMessageDialog(null, Enter a string,Input Demo, JOptionPane.QUESTION_MESSAGE);2 、 String string = JOptionPane.showInputDialog(null, Enter a string,Input Demo, JOptionPane.QUESTION_MESSAGE);3 、 String string = JOptionPane.showInputDialog(Enter

22、a string, InputDemo, 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 the following code.import javax.swing.*; public class ShowErrors public static void main(S

23、tring 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 、 The program cannot compile because i does not have an initial valuewhen it is

24、 used in i = i + 4;does notprogram3 、 The program compilesbut has a runtime error because ihave an initial value when it is used in i = i + 4; 4 、 The compiles and runs fine. 答案 2 第 39 題 Suppose x=10 and y=10. What is x after evaluating the expression (y 10) & (x- 10)?1 、 92 、 10 3 、 11 答案 2 第 40 題

25、Suppose x=10 and y=10 what is x after evaluating the expression(y = 10) | (x+ 10).1 、 92 、 10 3 、 11 答案 2 第 41 題 Suppose x = 1, y = -1, and z = 1. What isthe printout of the following statement? (Please indent the statementcorrectly first.) if (x 0) if (y 0)x 0 and y 0); else if (z 0)x 0);1、 x 0 and

26、 y 0;2、x 0;3、x 0 and z = 100) toohot); 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)print答案 1 2 3 第 54 題 How many times will the following code Welcome to Java?int count = 0; while(count 10) Welcome to Java); count+;1 、 82 、 93 、 104 、 11 5

27、 、 0 答案 3 第 55 題 Analyze the following count = 0; while(count 100) / Point AWelcome to Java!); 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 C 5、 count 100

28、is alwaysfalse at 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 、 82 、 93 、 104 、 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

29、(count+ 9);1 、 82 、 93 、 104 、 11 5 、 0 答案 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 第

30、 60 題 Analyze the following code: public class Test public static void main (String 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

31、4.3 、 The program compiles despite the semicolon (;) on the for loop line, and displays 14.4 、 The for loop in this program is same as for (i = 0; i 4) break; while (item 5);3、8 答案 2 第 63 題 After the continueouter statementisexecuted in the following loop, which statement is executed? outer: for (in

32、t i = 1; i 10; i+) inner:for (int j = 1; j 50)continue1 、 Thecontrolis in theouterloop,loop is executed.2 、 Thecontrolis in theinnerloop,loop is executed.3 、 The statement labeled next.4 、 Theprogramterminates.答案 1numberis 9. What is theoutputfromand thenextiterationoftheouterand thenextiterationoft

33、heinner第 64題Supposetheinputforrunningthe followingprogram?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 、 aaaaa2 、 aaaa3 、 aaa4 、 invalid call 答案 4 第 70 題Supposestatic void n

34、Print(String message, while (n 0) ; n-; What is k after invoking nPrint(A message, k)?int k = 2; nPrint(Amessage, k);1 、 02 、 13 、 2 4 、 3 答案 3 第 71 題 Analyze the following code: public class Test public static void main(String args) int n)int n)19, 500L);public static int xMethod(int n, long l) int

35、, long); return n; public static long xMethod(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 cann

36、ot distinguish which xmethod to invoke.答案 1 第 72 題 Analyze the following code. public class Test public static void main(String args) , 2);public static double max(int num1, double num2)if (num1 max(int, double) is invoked); num2) return num1; else return num2;public static double max(double num1, i

37、nt num2) max(double,int) is invoked);if (num1 23num2) return num1; else return num2;1、The program cannot compilebecause you cannot have the printstatement in a non-void method.2 、 The program cannot compile because the compiler cannot determine which max method should be invoked.3 、 The g

38、ramrunsandprints2followedbymax(int,double)is4 、 Theprogramrunsandprints2followedbymax(double,int)isinvoked.5 、 The program runs and prints max(int, double) is invoked followedby 2. 答案 2 第 73 題 The client can use a method without knowing how it is implemented. The details of the implementation are en

39、capsulated inthemethod andhiddenfromknown as 1、information hiding2、encapsulation3、method hiding4、simplifyingmethod答案2第 74題WhatMath.floor(3.6)?1、3.02、33、4 4 、 5.0答案 1第 751 is3.4, 2.0, 3.5, 5.5, list1 is the client who invokes the method.This is題 If you declare an array double list =1 、 3.42 、 2.03 、 3.44 、 5.5 5 、

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論