Java课后答案分析和总结.docx

上传人:太** 文档编号:72638637 上传时间:2023-02-13 格式:DOCX 页数:44 大小:154.69KB
返回 下载 相关 举报
Java课后答案分析和总结.docx_第1页
第1页 / 共44页
Java课后答案分析和总结.docx_第2页
第2页 / 共44页
点击查看更多>>
资源描述

《Java课后答案分析和总结.docx》由会员分享,可在线阅读,更多相关《Java课后答案分析和总结.docx(44页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Chapter 1 Introduction to Computers, Programs, and Java1. A computer is an electronic device that stores and processes data. A computer includes both hardware and software. In general, hardware is the physical aspect of the computer that can be seen, and software is the invisible instructions that c

2、ontrol the hardware and make it work. The hardware of a computer consists of a CPU, cache, memory, hard disk, floppy disk, monitor, printer, and communication devices.2. The machine language is a set of primitive instructions built into every computer. Assembly language is a low-level programming la

3、nguage in which a mnemonic is used to represent each of the machine language instructions. The high-level languages are English-like and easy to learn and program.3. The operating system (OS) is a program that manages and controls a computers activities. The examples of OS are Windows 98, NT, 2000,

4、XP, or ME. Windows.Application programs such as an Internet browser and a word processor run on top of an operating system.4. 100 in decimal = 64 in hex100 in decimal = 01100100 in binary4340 in decimal = 10F4 in hex4340 in decimal = lOOOOllllOlOOin binary2000 in decimal = 7D0 in hex5. 1000011001 in

5、 binary = 219 in hex1000011001 in binary = 537 in decimal100000000 in binary = 100 in hex100000000inbinary=256in decimal100111 in binary = 27 in hex100111 in binary = 39 in decimal6. FEFA9 in hex = 1044393 in decimal93 in hex = 147 in decimal93 in hex= 10010011 in binary2000 in hex=8192in decimal7.

6、Developed by a team led by James Gosling at Sun Microsystems in 1991. Originally called Oak, it became Java in 1995 when it was redesigned for developing Internet applications.Java can run on any platform with a Java Virtual Machine. The minimum requirement is the Java Runtime Environment, free from

7、 the .8. The input is the Java source code and the output is the Java bytecode (if compiled successfully).9. JBuilder by Borland, Sun ONE Studio by Sun, Cafe by WebGain, Visual Age for Java by IBM are the tools for developing J ava programs, not dialects of Java. These tools make developing Java pro

8、grams easier and more productive.10. HTML is a markup language for displaying static Web pages. Java is a full-fledged programming language that can be used to develop dynamic Web pages. The Java programs that run from a Web browser are called applets. Java applets must bei nt sum = 0;i nt number =

9、0;do number+;if (number != 10 & number != 11) sum += number; while (number 20);System.out.println(The sum is + sum);)The statement labeled next.14. The control is in the outer loop, and the next iteration of the outer loop is executed.15. Line 3: The semicolon (;)at the end of the for loop heading s

10、hould be removed. Line 4: sum not defined.Line 5 :the semicolon (;)atthe end of the if statement should be removed.Line 6: Missing a semicolon for the first printin statement.Line 6: j not defined.Line 10: The semicolon (;)atthe end of the while heading should be removed.Line 17: Missing a semicolon

11、 at the end of the while loop.16. (A) compile error: i is not initialized.(8) Line 3: The ; at the end of for loop should be removed.for (int i = 0; i *2*3 2*/| 32*(C).1xxx2xxx4xxx8xxx16xxx1xxx2xxx4xxx8xxx1xxx2xxx4xxxlxxx2xxxlxxx(D).1G1G3G1G3G5G1G3G5G7G1G3G5G7G9G19、(A)public class Test args)args)pub

12、lic static void main(String int i = 0;if (i 0)i + +;elsei-;char grade;if (i = 90)grade = 1A!;else if (i = 80)grade = 1B *;)(B)(B)public class Test public static void main(String args) for (int i = 0; i 0) i+; elsei一; )Chapter 6 Arrays1. See the section Declaring and Creating Arrays.12. You access an

13、 array using its index.3. No memory is allocated when an array is declared. The memory is allocated when creating the array.x i s 60The size of numbers is 304. Indicate true or false for the following statements:1. Every element in an array has the same type.Answer: True2. The array size is fixed af

14、ter it is declared.Answer: False3. The array size is fixed after it is created.Answer: True4. The element in the array must be of primitive data type.Answer: FalseWhich of the following statements are valid array declarations?i nt i = new i nt (30);Answer: InvaliddoubIe d 二 new doubIe30;Answer: Vali

15、dchar r = new char (1. . 30);Answer: Invalidint i=(3, 4, 3, 2);Answer: Invalidfloat f二2.3, 4.5, 5.6;Answer: Validchar c = new char 0 ;Answer: Invalid5. The array index type is int and its lowest index is 0.6. a 2A mntime exception occurs.7. Line 3: the array declaration is wrong. It should be double

16、. The array needs to be created before its been used. e.g. new double10Line 5: The semicolon (;)atthe end of the for loop heading should be removed.Line 5: r.length() should be r.length.Line 6: random should be random()Line 6: r(i) should be ri.8. System. ar raycopy (source, 0, t, 0, source, length)

17、;The second assignment statement myList = new int20 creates a new array and assigns its reference tomyList.False. When an array is passed to a method, the reference value of the array is passed. No new array is created. Both argument and parameter point to the same array.9. numbers is 0 and numbers0

18、 is 314.(A) Executing createAiiay in Line 6(B) After e?dtiiig createAnay in Line 6StackStackHeapStackSpace required for the createAiray method char chars: refSpace requiied for the main methodchar chars: refSpace required for the createAiray method char chars: refSpace requiied for the main methodch

19、ar chars: refArray of 100 charactersSpace required for the main methodchar chars: refArray of 100 characters(C) Executing displayAiray in Line 10(D) After exiting di splayAii ay in LineStackSpace required for the displayAn-ay method char chars: retSpace required for the main methodchar chars: refHea

20、pArray of 100 charactersStackHeap(E) ExecutingcountLetters in Line 13StackHeapSpace required for the main methodchaif chars: ref(F) After exiting coimtLetters in Line 13StackArray of 100 charactersHeapSpace required for the countLettei s method iiit counts: ref char chars: refSpace requiied for the

21、main methodiiit counts: ref char chars: refAiray of 100 chaiactersArray of 26integersJ,Array of 100Space requiied for the main methodint coiuits: ref char chars: reflArray of 26 integerscharacters(G) Executing displayCounts ill Line 18(H) After exiting displayCount,in Line 18StackSpace requiied for

22、the displayCoimts methodint counts: refcharactersAiray of 26 inteaersJ 一Space required for the main method int counts: re char口 chars: refHeapArray of 100StackSpace requiied for the main methodint coiuits: ref char chars: refArray of 100 charactersArray of 26 inteaers15. Only one variable-length par

23、ameter may be specified in a mthod and this parameter must be the last parameter. The method return type cannot be a variable-length parameter.16. The last oneprintMax(new2, 3);is incorrect, bcausa the array must of the doubl 口 type.17. Omitted18. OmittedOmitted19. Simply change (currentMax I istj)2

24、0. Simply change list k currentElement on Line 9 to list k trues2 = s3 = false51 .equals(s2) = true52 .equals(s3) = truesicomparTo(s2) = 053 pareTo(s3) = 0si = s4 = truesi.charAt(0) = Wsi indexOf(!j1) = -1si.indexOf(nton) = 8silast工ndxOf(a) = 14si.lastIndexOf(HoH, 15) = 9si.length () = 16si.substrin

25、g(5) = me to Java!si.substring (5, 11) = me tosi.startsWith(nWelH) = truesi. ends With (n Java11) = truesi.toLowerCase () = welcome to j ava!si.toUpperCase()= WELCOME TO JAVA!” Welcome n.trim() = Welcomesi.replace ( T o !, !T!) = WelcTme tT Java!si.replaceAll(non r nTn) = WelcTme tT Java!si.replaceF

26、irst(non, HTH) = WelcTme tT Java!si.toCharArray() returns an array of characters consisting of W, e, I, c, o, m,,t, o, , J, a, v, a(Not that none of th operation caus the contents of a string to change)String s = new Str i ng (new str i ng);Answer: CorrectStrings3 = sl +s2;Answer: CorrectStrings3 =

27、sl -s2;Answer: Incorrectsi =s2Answer: Correctsi =s2Answer: Incorrectsl pareTo(s2);Answer: Correctinti = sl.length();Answer: Correctcharc = sl(O);Answer: Incorrect char c = s 1 .charAt(s 1.length();Answer: Incorrect : its out of bounds, even if the preceding problem is fixed.3. Use the method equa I s I gnoreCase.4. Use the methods toUpperCase and toLowerCase. The conversion methods (toLowerCase, toUpperCase, trim, replace) don t change the contents of the string that invokes these methods. These methods create new strings.5. 0.6. Use the overloaded sta

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 解决方案

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁