Lesson 1 -- if, else
if
If the program says
if (name.equals("kangaroo")) {
System.out.println("You live in Australia!");
}
then if the name is "kangaroo", the Australia message will
be displayed.
if/else
If the program says
if (name.startsWith("q")) {
System.out.println("Your name starts with q -- how unusual!");
} else {
System.out.println("Your name starts with a non-q letter");
}
people with names starting with 'q' get a special message, everyone
else is told they have a non-q letter.
Problems
- Have the program print out a special welcome message like 'Good
luck' for people
with your name, but the normal welcome message for everyone else.
- Have the program give you the same number every time so you have
an easy time guessing.
Last modified on 12 Jun 2013 by AO
Copyright © 2024 Andrew Oliver