Tutorial 3 Exercises
- First, count the number of icons on your desktop. Make a program
that makes an int variable
x, sets it equal to the
number of icons on your desktop, and then make an if
statement that prints out "You have way too many
icons" if x > 10.
- Take the above program and turn it into an
if-else
statement, where the program prints out "Did you just install
your operating system or something?" in the
else part (or, basically, you have too few icons on
your desktop).
- Write a program that makes an int variable
num and
sets it equal to some large number (like 200). Then use an
if statement in a while loop that prints
out "num is an even number" if num
is even (hint: you can use (num % 2) == 0 to test
if num is even. The %
operator is the "modulo" operator, and it basically calculates the
remainder when dividing two numbers).