Cmps201 Lab 1
Cmps201 Lab 1
1. State whether each of the following is true or false. If false, explain why.
(a) Comments cause the computer to print the text after the // on the screen when the
program executes.
(b) All variables must be given a type when they’re declared.
(c) Java considers the variables number and NuMbEr to be identical.
(d) The println() function is used to display text on the screen in Java.
(e) The expression 5 + 3 * 2 evaluates to 16 in Java.
(f) An identifier in Java can start with a number, e.g., 3count.
(g) Syntax errors occur when the program runs but produces incorrect results.
(h) To include a double quote (") character within a string in Java, you can directly use
it without any special escape sequence.
2. Determine the values displayed when printing the following expressions in println state-
ments. Write your answers in the second column.
Expression Answer
(10 + 5) ∗ 2/5
8%3 + 7/2
15%4 − (2 + 3)/4
1+5∗5−6∗3
12/0
3. What is the output of the following expression and respond with “Error” for an invalid
expression:
Expression Output
System.out.println(1*3 + "I will
work on CS201");
System.out.println("CMPS 201" + 1 +
1);
System.out.println("CMPS 201" * 3);
4. Implement a Java program to print the following text (with the same layout):
"\n" represents a newline character.
"\t" represents a tab character.
"\\" represents a backslash character.
"\"" represents a double quote character.
5. Determine the values displayed when printing the following expressions in println state-
ments. Write your answers in the second column.
Expression Answer
49/5
10 + 100/10 ∗ 5 − 20.5/5
49.0/5
”CMPS” + 200 + 12 + ”L”
”CMPS” + (200 + 12) + ”L”
200 + 1 + "CMPS"
5.2 + 31/10
Best wishes
Page 2