Programming and Problem Solving with Java

(やまだぃちぅ) #1
713


  1. a. The Stringclass provides methods that can be used to compare two strings.
    b.


Method Name Argument Returns English Description
equals String boolean Returns trueif the two strings are equal,
falseotherwise.
equalsIgnoreCase String boolean Returns trueif the two strings are equal,
ignoring case of letters; falseotherwise.
compareTo String int Returns 0 : the two strings are equal.
Returns <0: object’s string comes before
argument’s string.
Returns >0: object’s string comes after
argument’s string.
toUpperCase none String Returns object’s string in all uppercase
letters.
toLowerCase none String Returns object’s string in all lowercase
letters.

Chapter 4 Programming Warm-Up Exercises


4.if(pageNumber % 2 == 0 )
leftPage = true;
We have to use the ifform here because the problem does not say to set leftPage
to falseif pageNumberis odd.
5.if(i > j)
if(i > k)
biggest = i;
else
biggest = k;
else
if(j > k)
biggest = j;
else
biggest = k;
or
biggest = i;
if(j > biggest)
biggest = j;
if(k > biggest)
biggest = k;
7.if(age > 64 )
System.out.print("Senior voter");
else if(age < 18 )
System.out.print("Under age");
elseSystem.out.print("Regular voter");
Free download pdf