Programming and Problem Solving with Java

(やまだぃちぅ) #1

204


b.Fill in the following table that describes methods that can be applied to
string objects.

Method Name Argument Returns English Description
equals
equalsIgnoreCase
compareTo
toUpperCase
toLowerCase

Programming Warm-Up Exercises


1.Declare eligibleto be a booleanvariable, and assign it the value true.
2.Write a statement that sets the booleanvariable availableto trueif numberOrdered
is less than or equal to numberOnHandminus numberReserved.
3.Write a statement containing a logical expression that assigns trueto the
booleanvariable isCandidateif satScoreis greater than or equal to 1100,gpais not
less than 2.5, and ageis greater than 15. Otherwise,isCandidateshould be false.
4.Given the declarations
booleanleftPage;
int pageNumber:
write a statement that sets leftPageto trueif pageNumberis even. (Hint:Consider
what the remainders are when you divide different integers by 2.)
5.Write an ifstatement (or a series of ifstatements) that assigns to the variable
biggestthe greatest value contained in variables i,j, and k. Assume the three
values are distinct.
6.Rewrite the following sequence of if-(then)as a single if-else.
if(year % 4 == 0 )
System.out.print(year + " is a leap year.");
if(year % 4 != 0 )
{
year = year + 4 – year % 4 ;
System.out.print(year + " is the next leap year.");
}
7.Simplify the following code segment, taking out unnecessary comparisons.
Assume that ageis an intvariable.
Free download pdf