




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、1) 2) 3) 4) 5) 6) 7) 8) 9) 10) 11) 12) 1. 2. 3. 4. 5. 6. 7. 8. 9. 填空題 數組的元素通過下標 來訪問,數組 Array的長度為Arrav.length 數組復制時,=將一個數組的引用傳遞給另一個數組。 JVM將數組存儲在 棧 (堆或棧)中。 數組的二分查找法運用的前提條件是數組已經排序 。 Java中數組的下標的數據類型是 整型。 數組最小的下標是0。 arraycopy()的最后一個參數指明復制元素的個數。 向方法傳遞數組參數時,傳遞的是數組的引用 。 數組初始化包括數組的申明,創建和初始化 。 數組下標訪問超出索引范圍時拋出
2、 數組越界異常 浮點型數組的默認值是O.Of 。 數組創建后其大小不能 改變。 選擇題 下面錯誤的初始化語句是_ABD_ A. char str=hello;B. char str100=hello; C. char str=h,e,T,T,o;D. char str=hello; 定義了一維int型數組a10后,下面錯誤的引用是 _B_ A. a0=1; B. a10=2;C. a0=5*2;D. a1=a2*a0; 下面的二維數組初始化語句中,正確的是 A. float b22=0.1,0.2,0.3,0.4; C. int a2= 1,2,3,4; 引用數組元素時,數組下標可以是 A.
3、整型常量B.整型變量 B. i nt a=1,2,3,4; D. float a22=0; D_ C. 整型表達式D.以上均可 11 / 10 定義了 int型二維數組a67后,數組元素a34前的數組元素個數為 A. 24B. 25C. 18D. 17 F列初始化字符數組的語句中,正確的是_B. B. char str=h,e,T,T,o,0; D. char str100=; C. 堆D.鏈表 A. char str5=hello; C. char str5=hi; 數組在Java中儲存在 C 中 A.棧B.隊列 下面程序的運行結果是 mai n() int a=1,2,3,4,5,6; S
4、ystem.out.pri ntf(%d, a11); A. 3 B. 4 C. 5 D. 6 F面程序的運行結果是_C. mai n() int x=30; int numbers=new intx; x=60; System.out.println(numbers.length); A. 60 B. 20 C. 30 D. 50 下面程序的運行結果是 _BDF_ main() char s1=ABCDEF.toCharArray(); int i=0; 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. while(s1i+!=0) System.out.pri
5、ntln(s1i+); A. ABCDEF B. BDF C. ABCDE 下面 不是創建數組的正確語句 C A.float f=new float66; C.float f=new float6; 下面不是數組復制方法的是 (C) A. 用循環語句逐個復制數組 C. 用 =進行復制 數組 a 的第三個元素表示為 D A. a(3)B. a3 當訪問無效的數組下標時,會發生 B A. 中止程序B. 拋出異常 D. BCDE B. float f=new float6; D.float f=new float6; B. 用方法 arraycopy D. 用 clone 方法 C. a(2)D.
6、a2 C. 系統崩潰D. 直接跳過 使用 arraycopy() 方法將數組 a 復制到 b 正確的是 A A. arraycopy(a,0,b,0,a.length) B. arraycopy(a,0,b,0,b.length) C. . arraycopy(b,0,a,0,a.length) 關于數組默認值,錯誤的是 B D. arraycopy(a,1,b,1,a.length) A. char-u0000B. Boolean-trueC. float-0.0fD. int- 0 關于數組作為方法的參數時,向方法傳遞的是 A A. 數組的引用 B. 數組的棧地址 C. 數組自身 D. 數
7、組的元素 關于數組復制,下列說法錯誤的是 AC A. = 可以實現數組復制 B. 運用循環語句進行數組復制必須兩個數組長度相同 C. arraycopy()方法沒有給目標數組分配內存空間 D. 數組復制是數組引用的傳遞 下列語句會造成數組 new int10 越界是 D A. a0 += 9; B. a9=10;C. a9D. for(int i=0;i=10;i+) ai+; 20.在JDK環境下編譯JAVA源程序使用的命令是(B ) A.javaB.javac C.jvm D. 子類不能使用父類的構造方法 D.tomcat 21. main 方法是 java Application 程序執
8、行的入口點。 關于 main 方法放入方法以下合法的是 A. public static void main(); B. public static void main(Stringargs) 22. 23. C. public static int main(String arg) D. public void main(String arg) 執行完代碼 int x=new int25; 后以下 ( A )說明正確的 A. x24為 0B. x24未定義C. x25為 0 關于數組排序方法,錯誤的是 C A. 選擇排序B. 插入排序 C. 二分排序 D. x0為空 D. 用 arrays.
9、sort( )排序 24. 關于 char 類型的數組,說法正確的是 A. 其數組的默認值是 A C. 數組不能轉換為字符串 B. 可以僅通過數組名來訪問數組 D. 可以存儲整型數值 25. 對于數組 a10 ,下列表示錯誤的是 A. a0B. a(0) 26. 下列數組聲明,下列表示錯誤的是 C. a9 D. a1 A. int a 三、是非題 B. int a C. int a D. inta 1.下標用于指出數組中某個元素位置的數字。 ( 2. 把數組中元素按某種順序排列的過程叫做查找。 3. 確定數組中是否含有某個關鍵字的過程叫做排序。 4. 一個數組可以存放許多不同類型的數值。 5.
10、 數組的下標通常是float 型。 () 6. 數組的某個元素被傳遞給一個方法并被該方法修改, 中含有修改過的數值。 () 當被調用方法執行完畢時,這個元素 7. 數組可以聲明為任何數據類型。() 8. 數組由具有一名字和相同類型的一組連續內存單元構成。() 9. 在數組聲明中可以用等號及一個逗號分隔的初始值表初始化數組元素, 用戶來決定。 () 該數組大小只能由 10. 將一個數組傳遞給一個方法,必須加在數組名后加方括號。 () 11. Java語言中的數組元素下標總是從0開始,下標可以是整數或整型表達式。() 12. 下面這條語句正確嗎? () double myList; myList
11、= 1.9, 2.9, 3.5, 4.6; 14. 數組中有length()這個方法,如 array.length()表示數組array中元素的個數() 15. 下面這條語句正確嗎 ?() int t32 = 1,2,3,4,5,6; 16. 數組聲明后其大小固定。 ( ) 17. 設有整型數組的定義: int A.=new int8; ,則 a.length 的值為 7。 ( ) 18. 數組一旦創建,其大小不能再改變。 ( ) 19. 用任何方式創建數組時,都必須指定數組的長度。 ( ) 20. 聲明數組時,要指定數組長度,以便為數組分配內存。 ( ) 四、簡答題 1. 如何聲明和創建一個
12、一維數組? 2. 如何訪問數組的元素? a 的第三個元素如何表示? 3. 數組下標的類型是什么?最小的下標是什么?一維數組 4. 數組越界訪問會發生什么錯誤?怎樣避免該錯誤? 5. 給方法傳遞數組參數與傳遞基本數據類型變量的值有何不同? 6. 復制數組有哪些方法? 8.聲明數組變量會為數組分配內存空間嗎?為什么? 五、程序題 1. 有一個整數數組,其中存放著序列1,3,5,7,9,11, 13,15,17,19。請將該序列倒 序存放并輸出。 1) public class Test 2) public static void main(String args) 3) int a = 1,3,5
13、,7,9,11,13,15,17,19; 4) int t; 5) System.out.println(”數組的初始狀態為:); 6) for (int i=0; i a.length; i+) 7) System.out.print( + ai); 8) System.out.println(); 9) 9) for (int i=0; i a.length/2; i+) 10) t = ai; 11) ai = aa.length-i-1; 12) aa.length-i-1=t; 13) 15) 14) System.out.println(數組逆序存放后的狀態為:); 15) for
14、 (int i=0; i a.length; i+) 16) System.out.print( + ai); 17) 18) 2. 編寫一個程序,提示用戶輸入學生數量姓名和他們的成績,并按照成績的降序來打印學 生的姓名。 1) public class exercise16 2) public static void main(String args) 3) String numberString = 4) JOptionPane.showInputDialog(Enter the number of students); 5) int numberOfStudents = Integer.
15、parseInt(numberString); 6) 7) String names = new StringnumberOfStudents; 8) double scores = new doublenumberOfStudents; 9) 10) for (int i = 0; i = 1; i-) 17) double currentMax = scores0; 18) int currentMaxIndex = 0; 19) 20) for (int j = 1; j = i; j+) 21) if (currentMax = 0; i-) 37) System.out.printl
16、n(namesi + t + scoresi); 38) 39) 40) 3. 編寫一個程序,使它能夠讀入 10 個整數,并且存儲其中互不相同的數,最后將這10 個數 輸出。 1) import javax.swing.JOptionPane; 2) 3) public class exercise5 4) 5) 6) 7) 8) 9) 10) 11) 12) 13) 14) 15) 16) 17) 18) 19) 20) 21) 22) 23) 24) 25) 26) 27) 28) 29) 30) 31) 32) 33) 34) 35) 36) 37) 38) 39) 40) 41) 42
17、) 43) 44) 45) private static int j = 0; public static void main(String args) int arrayInt = new int10; int i = 0; do String numberString = JOptionPane .showInputDialog(Enter a number: ); int number = Integer.parseInt(numberString); if (isNotHave(arrayInt, number) arrayInti = number; i+; j+; else do
18、numberString = JOptionPane .showInputDialog(This number is exit,enter a another number: ); number = Integer.parseInt(numberString); while (!isNotHave(arrayInt, number); arrayInti = number; i+; j+; while (i arrayInt.length); String output = ; for (int k : arrayInt) output += k + ; JOptionPane.showMes
19、sageDialog(null, The elements of arrayInt is + output, output arrayInt, JOptionPane.INFORMATION_MESSAGE); public static boolean isNotHave(int arrayInt, int n) for (int i = 0; i j; i+) 46) if (arrayInti = n) 47) return false; 48) 49) return true; 50) 51) 4.先對數組 1,3, 9,5,6,7,1,5,4,8進行排序,然后二分查找法找出數組中的元
20、素 8,標出其排序后其下標的位置。 1) public class Test 2) public static void main(String args) 3) int numbers = 1,3,9,5,6,7,1,5,4,8; 4) java.util.Arrays.sort(numbers); 5) 6) System.out.println(”排序后的數組為:); 7) for (int i=0; i low) mid = (mid = (low + high) / 2) ? 22) (mid + 1) : (low + high) / 2) 23) if (key = 0); 15
21、) 16) double average = (sum - scorescount) / (count - 1); 17) 18)int numOfAbove = 0; 19) int numOfBelow = 0; 20) for (int i = 0; i = average) 22) numOfAbove+; 23) else 24) numOfBelow+; 25) 26) System.out.println(Average is + average); 27) System.out.println(Number of scores above or equal to the ave
22、rage 28) + numOfAbove); 29) System.out.println(Number of scores below the average 30) + numOfBelow); 31) 32) System.exit(0); 33) 34) 6. 編寫一個程序,生成 0-9 之間的 100 個隨機整數并且顯示每一個數的個數。 1) public class exercise7 2) public static void main(String args) 3) int numbers = new int100; 4) int counts = new int10; 5)
23、 6) int k; 7) for (int i = 0; i 100; i+) 8) 9) numbersi = (int)(Math.random() * 10); 10) countsnumbersi+; 11) 12) 13)System.out.println(the 100 numbers is :); 14) 15) 16) 17) 18) 19) 20) 21) 22) 23) for(int i = 1; i = numbers.length; i+) if (i % 10 != 0) System.out.print(numbersi-1 + ); else System.
24、out.println(numbersi-1); System.out.println(the counts of each number is :); for(int i = 1; i = counts.length; i+) 24) System.out.print(countsi-1 + ); 25) 26) 7. 求平均值和方差。利用 mean(int numbers) 求平均值,利用 deviation(int numbers) 求標 準差。 1) import java.util.Scanner; 2) public class MeanDeviation 3) public st
25、atic void main(String args) 4) Scanner in = new Scanner(System.in); 5) 6) System.out.print(輸入數組的長度:); 7) int n = in.nextInt(); 8) 8) System.out.print(輸入數組元素:); 9) int array = new intn; 10) for (int i = 0; i array.length; i+) 11) 12) arrayi = in.nextInt(); 13) 15) 16) System.out.print(The mean is: + mean(array) + n 17) + The deviation is: + deviation(a
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 稀土金屬壓延加工中的質量改進方法選擇與實施考核試卷
- 游樂設施施工中的安全文化建設考核試卷
- 木片在紙漿生產中的優化研究考核試卷
- 搪瓷制品的環保生產與廢棄物處理考核試卷
- 生態保護宣傳教育策略考核試卷
- 青浦區高三語文二模2021作文
- 電飯煲煮飯不熟應對考核試卷
- 浙江省J12共同體聯盟校初三語文中考模擬考試試卷(含答案)
- 家用電器具的材料腐蝕與防護考核試卷
- 管道工程行業熱點問題研究動向與趨勢預測考核試卷
- 電力行業公共信用綜合評價標準(試行)
- 繼發性高血壓的診斷思路與流程
- 游標卡尺及螺旋測微器的讀數(共34張PPT)精選
- 上海市汽車維修結算工時定額(試行)
- 裝配式建筑發展存在的問題及對策分析
- 中國古典文獻學(全套)
- 自身免疫性腦炎
- 醫院質控科工作質量考核指標
- CRPS電源設計向導 CRPS Design Guide r-2017
- GB/T 4937.22-2018半導體器件機械和氣候試驗方法第22部分:鍵合強度
- GB/T 3452.2-2007液壓氣動用O形橡膠密封圈第2部分:外觀質量檢驗規范
評論
0/150
提交評論