COMP112 /14-T01b Programming I Test #1 (B) 2014-10-24 in Class
COMP112 /14-T01b Programming I Test #1 (B) 2014-10-24 in Class
COMP112 /14-T01b Programming I Test #1 (B) 2014-10-24 in Class
ve
gi
be
.
ll one t
i
w e le ork
k
m
w
ar o ou r
m py s r y ou
y
o
r co k o y
p
r
ze
COMP112/14-T01b Programming I
A you wo co
e
if ses on
el me
Test #1 (b)
so
2014-10-24
Due Date In Class
Class Code
Student No.
1. What is a bit ?
A binary digit
8
(1)
(2)
(3)
The fast storage cells in a CPU to hold operands and intermediate results are called:
registers
2. The Java compiler translates
Java source
(4)
Java class
files to
(5)
files.
How to state the external classes that your program refers to?
(6)
1) Line 1:
2) Line 2:
3) Line 2:
4) Line 3:
5) Line 4:
6) Line 4:
sc.nextDouble()
(8)
while ( a >= 0 )
a =
sc.nextDouble()
(9)
1/4
class
9ABC
_12_
100/10
MAX
float
number1020
(10)
(11)
(12)
(13)
(14)
7. If you enter 1 2 3 4, when you run this program, what will be the output?
import java.util.Scanner;
public class Four {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter four numbers: ");
int n1 = input.nextInt(), n2 = input.nextInt();
int n3 = input.nextInt(), n4 = input.nextInt();
double average = (n1 + n2 + n3 + n4) / 4;
System.out.println(average);
}
}
2.0
8. Write a statement to declare a constant STANDARD_NAME with value "Name".
38.5
(15)
12
(16)
-2
(17)
Determine whether the program is correct, if correct, write out the result, otherwise, point out
what the error is.
(18)
2/4
MPI.COMP112/14.T01b
30
(19)
(20)
(21)
(22)
(23)
(24)
(25)
(26)
(27)
(a = 10) + 20 / (9 - 5) * 4
10100
int x = 2, y = 1;
x *= x + y++ + 1;
14. Which of the following expressions are the same in terms of both side-effects and results?
(A) z = z+1
(B) ++z
(C) z++
c = (char)i;
17. The following code prints:
1.5
18. Write a statement to declare a long integer variable n and initialize it to 123456789000.
long n = 123456789000L;
20. Write an expression to determine whether variable x is greater than 100 and is a multiple of 4.
a Boolean literal
(28)
(29)
(30)
(31)
24. Suppose income is 20001. Will anything be displayed by the following statement? If yes, what
will that be?
if (income > 10000)
System.out.println("Income is greater than 10000");
else if (income > 20000)
System.out.println("Income is greater than 20000");
(32)
(33)
(34)
50
26. How many times will the following code print "Hello world!"?
int count = 50;
while ( count > 0 ) {
System.out.println("Hello world!");
count--;
}
27. The following code prints all the digits in a string. Complete the code.
for ( int i = 0; i < s.length();
char c =
++i
(35)
s.charAt(i)
(36)
) {
System.out.print(c);
(37)
300
(38)
29. The following computes this series for 100 items and stores the result in s . Complete the code.
1 + 3 + 7 + 13 + 21 + 31 + 43 +
int s =
(39)
, t =
(40)
, d =
(41)
s = s+t; t =
t+d
(42)
; d =
d+2
(43)
2
3 2
4 3 2
5 4 3 2
1
1
1
1
1
");
(44)
4/4