Java Reference
In-Depth Information
55
.
In Java, a semicolon is used to terminate a statement. The semicolon in Java
is called the statement terminator.
56
.
A file containing a Java program always ends with the extension
.java
.
57
.
Prompt lines are executable statements that tell the user what to do.
58
.
Corresponding to five arithmetic operators
+
,
-
,
*
,
/
, and
%
, Java provides
five compound operators
+=
,
-=
,
*=
,
/=
, and
%=
, respectively.
2
EXERCISES
1.
Mark the following statements as true or false.
a.
An identifier can be any sequence of digits and letters.
b.
In Java, there is no difference between a reserved word and a prede-
fined identifier.
c.
A Java identifier can start with a digit.
d.
The operands of the modulus operator must be integers.
e.
If the value of
a
is
4
and the value of
b
is
3
, then after the statement
a = b;
the value of
b
is still
3
.
f.
In an output statement, the newline character may be a part of the string.
g.
The following is a legal Java program:
public class
JavaProgram
{
public static void
main(String[] args)
{
}
}
h.
In a mixed expression, all operands are converted to floating-point
numbers.
i.
Suppose
x = 5
. After the statement
y = x++;
executes,
y
is
5
and
x
is
6
.
j.
Suppose
a = 5
. After the statement
++a;
executes, the value of
a
is still
5
because the value of the expression is not saved in another variable.
2.
Which of the following are valid Java identifiers?
myFirstProgram
MIX-UP
JavaProgram2
a.
b.
c.
quiz7
ProgrammingLecture2
1footEquals12Inches
d.
e.
f.
Mike'sFirstAttempt
Update Grade
4th
g.
h.
i.
j.
New_Student
3.
Which of the following is a reserved word in Java?
int
INT
Char
CHAR
a.
b.
c.
d.
4.
What is the difference between a keyword and a user-defined identifier?
Search WWH ::
Custom Search