1. Response to the following statements by
circling either T (TRUE) or F (FALSE). [10M]
I.
Java enables users to develop and
deploy applications on the Internet for servers, desktop computers, and small
hand-held devices.( T / F)
II.
Java is one of language that support
object oriented programming. ( T / F)
III.
Object-oriented programming (OOP)
is a popular programming approach that is replacing traditional procedural
programming techniques. ( T / F)
IV.
Reserved words or keywords are
words that have a specific meaning to the compiler and cannot be used for other
purposes in the program. ( T / F)
V.
System.out.println
is one of the pre-defined methods in Java. ( T / F)
VI.
The main method looks like this: (
T / F)
|
VII.
An identifier is a sequence of
characters that consist of letters, digits, underscores (_), and dollar signs
($).( T / F)
VIII.
An identifier must start with a
letter, an underscore (_), or a dollar sign ($). It cannot start with a digit. (
T / F)
IX.
An identifier in java can be of
any length. ( T / F)
X.
Logic Errors Produces incorrect
result. ( T / F)
2. Match the following Statement
/ Name to its description. [7M]
No
|
Statements
|
|
Description
|
I.
|
x = 1;
|
|
Constants
|
II.
|
int x = 1;
|
|
Addition
|
III.
|
double radius;
|
|
Declaring and Initializing
|
IV.
|
final int SIZE = 3;
|
|
Multiplication
|
V.
|
+
|
|
Assignment Statements
|
VI.
|
*
|
|
Remainder
|
VII.
|
%
|
|
Declaring Variables
|
3. Give a brief
explanation for the following questions.
I.
What is debugging? [2 marks]
II.
What is the difference between a constant and
a variable? [2 marks]
III.
Can Java run on any machine? What is needed to
run Java on a computer? [4 marks]
IV.
Explain the Java keywords. List any five Java
keywords. [4 marks]
V.
What is the Java source filename extension, and
what is the Java bytecode filename extension?
4. Evaluate the following expressions:
[3 marks]
I.
10 + 3 / 2
II.
3 * 3 + 3 % 2
III.
3 + 2 / 2 + -2 * 4
5. Evaluate the following boolean
expressions.
[5
marks]
username=1001;
password =
234;
EXAMPLE if(username==1001) TRUE
I.
if(password==234)
II.
if((username==1001) &&(password==234))
III.
if((username==1001)&&(password==789))
IV.
if((username==1001)||(password==789))
V.
if! (username==1001)
EXAMPLE Write
a for
statement to print integer 1 to 20.
int I;
For (i=1; i<=10; i++)
System.out.Println(i);
I.
Write a for statement to print integer 50 to
60. (3 marks)
II.
Write a for statement to print the following
output. (3 marks)
2
4 6 8 10
EXAMPLE Write a while statement to add numbers 11
through 20.
int sum
=0;
int
counter = 11;
while
(counter <=20)
{
sum = sum
+ counter;
counter++;
}
III.
Write a while statement to add ODD numbers
11 through 10. [5M]
IV.
Write a while statement to continuously read
in integers and stop when a negative number is entered. [5 marks]
8. (Counting positive) Write an algorithm (pseudocode or
flowchart) and java program that reads an unspecified number of
integers, determines how many positive have been. Your program ends with the
input 0.
No comments:
Post a Comment