You are on page 1of 2

95 學年 上學期 金門技術學院 資管系 日四技 一年級 程式設計 期中考 出題者 : 陳鍾誠

學號 : 姓名 : 分數 :

1 變數宣告
(a). 請選出可以做為變數名稱的項目並打勾. (10%) (b). 請宣告下列變數 (10%)
(1) ( ) static (1) 請宣告一個整數 x
int x;
(2) ( ) xxx (2) 請宣告一個字元 x,並將其初始值設定為 'c'.
char x = 'c';
(3) ( ) gx/kb (3) 請宣告一個布林值 x,並將其初始值設為 false.
boolean x = false;
(4) ( ) 20E5 (4) 請宣告一個浮點數 pi ,並將其初始值設為 3.1416
double pi = 3.1416;
(5) (  ) jack (5) 請宣告一個字串 s, 並將其初始值設定為 "Mary".
String s = "Mary";

2 請寫出下列範例的輸出結果 (列印值)
(a). 加減乘除 (10%) (c). 運算 (10%)
class TestOp1 { class TestOp2 {
public static void main(String args[]) { public static void main(String args[]) {
int a = 11, b = 4; boolean x=true, y=true;
b = a-b; System.out.println("x = "+x);
System.out.println("a= "+a); System.out.println("x&&false = "+(x&&false));
a = a*2; System.out.println("x||false = "+(x||false));
System.out.println("b= "+b); x = !x;
a += 3; System.out.println("x = "+x);
System.out.println("a= "+a); x = (!x && y);
b %= 5; System.out.println("x = "+x);
System.out.println("b= "+b); }
a = b*b; }
System.out.println("a= "+a);
} 輸出結果
} x = true
輸出結果 x&&false = false
a= 11 x||false = true
b= 7 x = false
a= 25 x = true
b= 2
a= 4

3 程式架構 (10%)
(a). 請於右格中寫出一個完整的 Java 程式,可以印 class VeryGood {
出 “Very Good”,並將檔案存為 VeryGood.java public static void main(String args[]) {
(4%) System.out.println("Very Good");
}
(b). 請寫出你用來編譯該程式的指令 (3%) }
javac VeryGood.java
(c). 請寫出你用來執行該程式的指令 (3%)
java VeryGood
95 學年 上學期 金門技術學院 資管系 日四技 一年級 程式設計 期中考 出題者 : 陳鍾誠
學號 : 姓名 :

4 基本控制邏輯 (20%)
(a) score 是一個成績,請利用邏輯判斷 if ,根 (b). 請寫出一個程式,計算 1/1 + 1/2 + …+ 1/100 的結果值並印
據 score 的值印出 『及格』 或 『不及格』 (註: 出. (10%)
60 分以上為及格。) (10%)
class Score1 { class Sum1 {
public static void main(String[] args) { public static void main(String[] args) {
int score = ??; double sum = 0.0;
if (score >= 60) for (int i=1; i<=100; i++)
System.out.println("及格"); {
else sum += 1.0/i;
System.out.println("不及格"); }
} System.out.println("1/1+1/2+...+1/100="+sum);
} }
}

5 活用題 (20%)
(a) 請寫出一個程式印出所有的 Unicode 字元 (b). 請寫出一個程式,計算小於 1000 的數值中,包含了幾個 6 與
(提示:Unicode 的範圍從 0 到 65535) (10%) 14 的公倍數. (10%)
class Unicode1 { class Lcm1 {
public static void main(String[] args) { public static void main(String[] args) {
for (int i = 0; i<=65535; i++) int count = 0;
{ for (int i=1; i<=1000; i++)
char c = (char) i; {
System.out.println(c); if (i %6 == 0 && i % 14 == 0)
} count = count + 1;
} }
} System.out.println("1..1000 有"+count+"個 6 與 14 的公倍
數");
}
}

6 除錯題 (5%)
請圈選出右列 Java 程式中錯誤的項目(共有 public class 327 {
五個),並註明正確的寫法 (本程式所想要產 public static void main(String args[]) {
生的輸出結果為 x = 9) int x = 9;
IF (x > 5)
1. 327  TestClass {
2. IF  if system.out.println("x="&x);
3. system  System }
4. &+ }
5. }  去掉 }
}

You might also like