文档详情

java编程题90道(国外英文资料).doc

发布:2017-06-05约1.86万字共20页下载文档
文本预览下载声明
java编程题90道(国外英文资料) Complete array int [] a = {100, 40, 60, 87, 34, 11, 56, 0} quicksort, bubble sort; 1) quick sort Package the SRC; / * * there are several key points * what is the middle value of * 1 * what is the comparison between the two I and j What is the left and right value of the recursive call * / Public class QuickSort {/ / QuickSort Public static void main (String [] args) Int [] a = {100, 40, 60, 87, 34, 11, 56, 0}; Int left = 0; Int right = a.l ength - 1; QuickSort (a, left, right); / / the loop displays the array For (int I = 0; I a.ength; I + +) { The System is out of order. } } Public static void quickSort (int [] a, int left, int right) { Int middle, temp; Int I = left; Int j = right; Middle = a [left]; While (I j) { While (a [I] middle). I++; } (a [j] , middle) and (j , left)) J --; } If (I = j) { Temp = a [I]; A [I] = a [j]; A [j] = temp; I++; J --; } } If (left j) { QuickSort (a, left, j); } If (right I) QuickSort (a, I, right); } } } 2) bubble sort Package the SRC; Public class PopSort { Public static void main (String [] args) Int [] a = {100, 40, 60, 87, 34, 11, 56, 0}; For (int I = 0; I a.i.ength; I + +) For (int j = 0; j) If (a [j] a [j + 1]) {... Int temp = a [j]; A [j] = a [j + 1]; A [j + 1] = temp; } } For (int k = 0; k a.ength; k + +) {. A. out.print (a [k] + ); } } } Using a semi-lookup algorithm, query to a certain number in an array; In the Chinese context, there are strings that sum up the data of each byte. Get rid of the value = 0 in an array, and store a new array of values that are not 0, such as: Int a [] = {1, 3, 4, 5, 0, 0, 6, 6, 6, 7, 7, 7, 6, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7, 7, 6, 7, 7, The generated new array is: Int b [] = {1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 5} Define 10 length Student arrays, add 1 to the age of 10 Student objects, and print out the details of 10 Student objects (array and ArrayList implementation). } 6. There are workers, farmers, teachers, scientists, waiter, among them, workers, farmers, the wait
显示全部
相似文档