Practice Challenges for Fun
In this lesson, we will go through some challenges using Java arithmetic expressions.
Quiz
Attempt the following quiz questions and check your understanding of Arithmetic Expressions.
What is the value of each of the following Java expressions?
17 + 2 – 5 / 5
18
16
4
3
Classify each of the following Java assignment statements as either legal or illegal. Let b
, s
, i
, l
, f
, and d
be variables of type byte
, short
, int
, long
, float
, and double
, respectively.
d = l
Legal
Illegal
If i
, l
, f
, and d
are variables of type int
, long
, float
, and double
, respectively, what is the data type of each of the following expressions?
f + d
int
long
float
double
Using Zeller’s congruence, what is the day of the week for March 17, 2020?
f = d + [(26 × (m + 1)) / 10] + y + [y / 4] + 6 × [y / 100] + [y / 400]
Monday
Tuesday
Wednesday
Thursday
Challenge 1: Find the cube
Write a Java statement that computes the cube of an integer ...