課程名稱︰計算機程式設計
課程性質︰通識課程
課程教師︰黃俊郎
考試日期(年月日)︰96 年 10 月 30 日
考試時限(分鐘):35 分
考試規則:可參考上課講義或相關書籍,但不可使用Compiler或IDE
是否需發放獎勵金:是
(如未明確表示,則不予發放)
試題 :
Problem 1 (15 pts.)
Write the following mathematical expressions in Java.(參照第二題的形式)
s = s0 + v0t + 1/2gt^2
Problem 2 (15 pts.)
Write the following Java expression in mathematical notation.
dm = m * ((Math.sqrt(1 + v/c)/Math.sqrt(1 - v/c)) - 1);
Problem 3 (25 pts.)
What are the values of the following expressions? In each line, assume that:
int x = 3;
int y = 5;
double z = 2.0;
1. 5 * x + y + z * 2
2. x * 3 / y * 2
3. x * 2 / x % (x * 2)
4. (3 + x) / z
5. (1.5 * x / y) / (3 + y)
Problem 4 (10 pts.)
Which of the following identifiers are valid?
1. public
2. a++
3. _xyz
4. 3Q
5. ThisIsAVeryLongVariableName
6. 4#R
7. $TRUE
8. PUBLIC
9. null
10.__US$
Problem 5 (15 pts.)
Evaluate the following expressions:(下面都是字串,請寫出字串輸出的結果)
1 + "Welcome" + 1 + 1
1 + "Welcome" + (1 + 1)
1 + "Welcome" + "\n" + 1
Problem 6 (20 pts.)
The following program is intended for converting feet into meters. The
program prompts the user to enter a number in feet, converts it into meters,
and display the result. For example, if the user enters "10." One foot is
0.305 meters. (The underlined statement converts a string to a double number.
It is correct.)
1. public class FootToMeter{
2. public static void main(String[] args){
3. String input =
4. JOptionPane.showInputdialog("Enter a number:");
5. double feet = Double.parseDouble(input);
﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉﹉
6. double meter = 0.35 * feet;
7. string message =
8. meter + " feet = " + feet + " meters.";
9. JOptionPane.showMessageDialog(
10. null,message,"P 6";
11. JOptionPane.INFORMATION_MESSAGE);
12. System.exit(0);
13. }
14. }
1.What's the file name that you should use to save this program file? (5pt)
2.Identify and fix the syntax errors in this program. (6pt)
3.Identify and fix the logic errors in this program. (9pt)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.32.84