Java Reference
In-Depth Information
8.
if
(n < 0)
System.out.println(n + " is less than zero.");
else
if
(n < 100)
System.out.println(
n + " is between 0 and 99 (inclusive).");
else
System.out.println(n + " is 100 or larger.");
9.
Some kind of B.
10.
Oranges
11.
Plums
12.
Fruitless
13.
n1 >= n2
14.
if
(n1 >= n2)
System.out.println("n1");
else
System.out.println("n2");
15.
When the variables are of type
int
, you test for equality using
==
, as follows:
variable1 == variable2
When the variables are of type
String
, you test for equality using the method
equals
, as follows:
variable1.equals(variable2)
In some cases, you might want to use
equalsIgnoreCase
instead of
equals
.
16.
if
(nextWord.compareToIgnoreCase("N") < 0)
System.out.println( "First half of the alphabet");
else
System.out.println("Second half of the alphabet");
17.
if
( (exam >= 60) && (programsDone >= 10) )
System.out.println("Passed");
else
System.out.println("Failed");
18.
if
( (pressure > 100) || (temperature >= 212) )
System.out.println("Emergency");
else
System.out.println("OK");
19.
a.
true
.