- 1、本文档共5页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Java部分答案
2.1 (Y. Daniel Liang英文版八版 P232:6.16) (Execution time) Write a program that randomly generates an array of 100000 integers and a key. Estimate the execution time of invoking the linearSearch method in Listing 6.6. Sort the array and estimate the execution time of invoking the binarySearch method in Listing 6.7. You can use the following code template to obtain the execution time:
long startTime = System.currentTimeMillis();
perform the task;
long endTime = System.currentTimeMillis();
long executionTime = endTime - startTime;
2.2 (Y. Daniel Liang英文版八版 P232:6.17 ) (Revising selection sort) In§6.10.1, you used selection sort to sort an array. The selection-sort method repeatedly finds the smallest number in the current array and swaps it with the first number in the array. Rewrite this program by finding the largest number and swapping it with the last number in the array. Write a test program that reads in ten double numbers, invokes the method, and displays the sorted numbers.
然后使用java.util.Arrays类的排序方法,并进行对比。
2.3 (Y. Daniel Liang英文版八版 P232: 6.19) (Sorting students) Write a program that prompts the user to enter the number of students, the students’ names, and their scores, and prints student names in decreasing order of their scores.
2.4 (Y. Daniel Liang英文版八版 P233:6.27 Identical arrays) Two arrays list1 and list2 are identical if they have the same contents. Write a method that returns true if list1 and list2 are identical, using the following header:
public static boolean equal(int[] list1, int[] list2)
Write a test program that prompts the user to enter two lists of integers and displays whether the two are identical. Here are the sample runs. Note that the first number in the input indicates the number of the elements in the list.
//6.16
package foundation;
import java.util.*;
class home{
public static int LinearSearch(int[] list, int key){
for(int i=0;ilist.length;i++){
if(key == list[i])
return i;
}
return -1;
}
}
public class homework1 {
publ
文档评论(0)