<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Java 基礎語法測試 > 考試說明:本次測試卷一共25道測試題,共計100分。考試時間120分鐘。 ## 一、選擇題(每題2分) 1. 下列屬于合法的 Java 標識符是(A) ~~~ A. _cat B. 5books C. static D. -3.14 ~~~ 2. 下列哪一個選項不是 Java 的關鍵字(C) ~~~ A. class B. package C. Void D. static ~~~ 3. 已知如下代碼,哪個選項中填寫到(1)(2)位置處,能滿足需求(C) ~~~ public static void main(String[] args) { // 求數組中偶數的和 (1) for (int i = 0; i < a.length; i++) { (2) sum = sum + a[i]; } } } ~~~ ~~~ A. (1) int sum; (2) if (a[i] % 2 == 0) { B. (1) int sum; (2) if (a[i] % 2 != 0) { C. (1) int sum = 0; (2) if (a[i] % 2 == 0) { D. (1) int sum = 0; (2) if (a[i] % 2 != 0) { ~~~ 4. 下面代碼的輸出結果為(D) ~~~ System.out.println(14 % 5); ~~~ ~~~ A. 14 B. 2.8 C. 2 D. 4 ~~~ 5. 執行下面語句后,b,x,y 的值分別是(B) ~~~ int x = 6, y = 8; boolean b = x > y && ++x == --y ~~~ ~~~ A. true, 6, 8 B. false, 6, 8 C. true, 7, 7 D. fasle 7, 7 ~~~ 6. 若 `a = 10`,`b = 20`,表示 x 在 a,b 之間的表達式為(A) ~~~ A. x >= a && x <= b B. x >= a || x <= b C. a <= x && x <= b D. a <= x <= b ~~~ 7. 若所用變量都已正確定義,以下選項中,非法的表達式是(C) ~~~ A. a != 4 || b == 1 B. 'a' % 5 C. 'a' = 2 / 5 D. 'C' + 35 ~~~ 8. 以下哪個不是合法的`int`類型字面量的表達方式(D) ~~~ A. 0x34 B. 026 C. 1000 D. 0x23dfL ~~~ 9. 關于變量的定義的說法正確的是(B) ~~~ A. n = 3; 表示 n 和 3 相等。 B. int n = 3; 該語句表示定義變量的同時進行初始化。 C. Java 中的變量可以不定義就直接賦值。 D. int 3 = n; 該語句合法。 ~~~ 10. 關于字符類型,以下說法正確的是(D) ~~~ A. 字符類型常量使用雙引號引起來,如 "D" B. ASCII 碼可以表示中文 C. 可以將任意整數賦值給字符變量而報錯 D. '@' 是一個字符型字面量的正確表示方式 ~~~ 11. 關于常量的說法錯誤的是(D) ~~~ A. final 是定義常量的關鍵字 B. 常量一旦定義就不可以改變 C. 常量名中的字母一般都大寫 D. final A = 4; 定義了一個常量 A ~~~ 12. 下列哪個不是程序的流程控制結構(B) ~~~ A. 順序結構 B. 嵌套結構 C. 選擇結構 D. 循環結構 ~~~ 13. 關于選擇結構下列哪個說法是正確的(B) ~~~ A. if 語句和 else 語句必須成對出現 B. if 語句可以沒有 else 語句對應 C. switch 結構中每個 case 語句中必須用 break 語句 D. switch 結構中必須有 default 語句 ~~~ 14. 已知如下代碼,當`n`為何值時,程序段將只輸出字符串`second`(BC) ~~~ switch (n) { case 0: { System.out.println("first"); } case 1: {} case 2: { System.out.println("scecond"); break; } defalut: { System.out.println("end"); } } ~~~ ~~~ A. 0 B. 1 C. 2 D. 以上都可以 ~~~ 15. 已知如下代碼,則方法調用錯誤的是(D) ~~~ public class Test { public static int sum(int a, int b) { return a + b; } public static void main(String[] args) { int m = 5, n = 4; // 方法調用 } } ~~~ ~~~ A. sum(6, 8); B. sum(m, n); C. sum(0x12, 0x34); D. sum(10L, 30L); ~~~ ## 二、代碼閱讀題(每題4分) 1. 以下代碼的輸出結果是(s = 180) ~~~ public static void main(String[] args) { int s = 0; int[] arr = {10, 20, 30, 40, 50, 60, 70, 80, 90}; for (int i = 0; i < arr.length; i++) { if (arr[i] % 3 == 0) { s += arr[i]; } } System.out.println("s = " + s); } ~~~ 2. 以下代碼的輸出結果是(80,2) ~~~ public static void main(String[] args) { int a = 80; System.out.println(a++); int b = (a / 3) % 5; System.out.println(b); } ~~~ 3. 以下代碼的輸出結果是(i = 5) ~~~ public static void main(String[] args) { int i = 1; int j = i++; if (i == ++j && i++ == j) { i += j; } System.out.println("i = " + i); } ~~~ 4. 以下代碼的輸出結果是(35) ~~~ public static int calc(int temp) { if (temp > 0) { return temp * 2; } return -1; } public static void main(String[] args) { System.out.println(calc(10) + calc(8) + calc(-10)); } ~~~ 5. 以下代碼的輸出結果是(2500) ~~~ public static void main(String[] args) { int sum = 0; for (int i = 0; i < 100; i++) { if (i % 2 == 0) { continue; } sum += i; } System.out.println(sum); } ~~~ ## 三、編程題(每題10分) 1. 控制臺輸入0~100之間的整數,當輸入`90~100`時,輸出`A`;輸入`80~90`時,輸出`B`;輸入`70~80`時,輸出`C`;輸入`60~70`時,輸出`D`;輸入`0~60`時,輸出`E`。 ~~~ public static void main(String[] args) { System.out.println("請輸入一個0~100之間的數"); Scanner scanner = new Scanner(System.in); int num = scanner.nextInt(); if (num < 0 || num > 100) { System.out.println("輸入數字超出范圍"); } else if (num >= 90) { System.out.println("A"); } else if (num >= 80) { System.out.println("B"); } else if (num >= 70) { System.out.println("C"); } else if (num >= 60) { System.out.println("D"); } else { System.out.println("E"); } } ~~~ 2. 控制臺輸入兩個大于0的整數,輸出兩個整數之間的所有質數。 ~~~ public static boolean prime(int m) { boolean flag = true; for (int i = 2; i < m / 2; i++) { if (m % i == 0) { flag = false; break; } } return flag; } public static void judge(int begin, int end) { for (int i = begin; i <= end; i++) { if (prime(i)) { System.out.println(i); } } } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("請輸入第一個的數"); int first = scanner.nextInt(); System.out.println("請輸入第二個的數"); int second = scanner.nextInt(); if (first > second) { judge(second, first); } else { judge(first, second); } } ~~~ 3. 略 4. 已知一個數組(數據類型可自定),將這個逆轉數組。 ~~~ public static void reverse(int[] arr) { for (int i = 0; i < arr.length / 2; i++) { int temp = arr[i]; arr[i] = arr[arr.length - 1 - i]; arr[arr.length - 1 - i] = temp; } } ~~~ 5. 打印出所有的"水仙花數",所謂"水仙花數"是指一個三位數,其各位數字立方和等于該數本身。例如:153是一個"水仙花數",因為153=1的三次方+5的三次方+3的三次方。 ~~~ public static void main(String[] args) { for (int i = 100; i <= 999; i++) { int x = i % 10; int y = i / 10 % 10; int z = i / 10 / 10 % 10; int num = x * x * x + y * y * y + z * z * z; if (num == i) { System.out.println(i); } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看