Professional Documents
Culture Documents
學號 : 姓名 : 分數 :
請填寫下列空格
1. (10%) 2. (10%)
public class Exam1 { public class Exam2 {
public static void main(String args[]) { public static void main(String args[]) {
int x = 5;
int x = 5, y = 2; System.out.println("x="+x);
System.out.println("x%y="+(x%y)); callByValue(x);
System.out.println("x>y="+(x>y)); System.out.println("x="+x);
int [] a = {5, 5};
System.out.println("x<y="+(x<y));
System.out.println("a[0]="+a[0]);
System.out.println("x*3+y*5="+(x*3+y*5)); callByAddress(a);
System.out.println("x*3/5="+(x*3/5)); System.out.println("a[0]="+a[0]);
} System.out.println("a[1]="+a[1]);
}
} static void callByValue(int x) {
x = 9;
}
static void callByAddress(int[] a) {
a[0] = 9;
}
}
Exam1 的輸出 : Exam2 的輸出 :
x%y = 1 x= 5
x>y = true x= 5
x<y = false a[0] = 5
x*3+y*5 = 25 a[0] = 9
x*3/5 = 3 a[1] = 5
1
金門技術學院 資管系 夜二技一年級 物件導向程式設計 93 下學期 期中考 出題者 : 陳鍾誠
學號 : 姓名 : 分數 :
7. 請利用 if 寫出 min(a,b,c) 函數,可傳回兩個整數 a,b, c 中的最小值 (10%)
int min(int a, int b, int c) {
範例 : // 請填入程式碼於此區域
int m = a;
呼叫 min(3, 5, 7) 會傳回 3 if (m > b)
呼叫 min(9, 2, 8) 會傳回 2 m = b;
if (m > c)
請將答案填入右格中 m=c
return m;
}
9. 遞迴函數