作者jlwhales (Juka)
看板NTU-Exam
标题[试题] 黄俊郎 97上 计算机程式设计 小考
时间Thu Nov 20 11:37:43 2008
课程名称︰计算机程式设计
课程性质︰通识A6
课程教师︰黄俊郎
开课学院:
开课系所︰
考试日期(年月日)︰97.11.13
考试时限(分钟):约60分
是否需发放奖励金:是
(如未明确表示,则不予发放)
试题 :
Problem 1 (20 pts)
The following program (AverageOfThree.java) is supposed to perform
the following tasks:
1. Ask the user to enter three integers, one by one.
2. Compute the average of the three integers
3. Print out the average.
Identify and correct the syntax and grammar errors.
public class Average{
public void main(String[] arg){
int sum = 0; ///this stores the accumulated sum
int i = 0; /* this controls # of iterations
while{i < 3}{
input =
JOptionPane.showInputDialog("Enter a number);
sum += Integer.ParseInteger(input);}
average = sum/3;
string message = "The average is: " + average + ".";
JOptionPane.showInformationMessage{
null;
message,
"Average of Three",
JOptionPan.INFORMATION_MESSAGE);
System.exit(0);
}
}
Problem 2 (30 pts)
What do the following expressions evaluate to?(int a = 3, b = 4, c = 5, d=6)
1. a+b*c
2. b-c%d
3. 45 + 42 % 5 * (23 % 3 * 2)
4. "The answer is: " + 5 % 2 + 3 / 2
5. "Good morning".indexOf("oo");
6. "Hello".equalsIgnoreCase("hell");
7. (3 * 9) > (100 % 4)
8. (a>3) && (b<5) || !(a == b)
9. (a == b) || ((b+c) / 3 == a)
10. (a += c) == (b *= 2)
Problem.3 (20pts+10 bonus pts)
Write a program "LargestAbsoluteOfThree.java" that performs the following
tasks:
1. Ask the user to enter three integer, say a, b, and c, one bu one.
2. Print out the largest absolute value of a, b, and c.
For example, if a=3, b=-4, and c=2, you should print out:
The largest absolute value is 4.
Bonus (10 pts): also print out which integer (1st, 2nd, or 3rd) has
the maximum value. Following the above example, you should print out:
The 2nd integer has the largest absolute value 4.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.7.139