203
if(typeA || typeB)
if(typeA && typeB)
System.out.print("Type AB");
else
System.out.print("Type O");
15.The nested ifstructure below has five possible branches depending on the
values read into charvariables ch1,ch2, and ch3. To test the structure, you need
five sets of data, each set using a different branch. Create the five test data sets.
if(ch1 == ch2)
if(ch2 == ch3)
System.out.print("All initials are the same.");
else
System.out.print("First two are the same.");
else if(ch2 == ch3)
System.out.print("Last two are the same.");
else if(ch1 == ch3)
System.out.print("First and last are the same.");
else
System.out.print("All initials are different.");
a.Test data set 1: ch1= ch2= ch3=
b.Test data set 2: ch1= ch2= ch3=
c. Test data set 3: ch1= ch2= ch3=
d.Test data set 4: ch1= ch2= ch3=
e.Test data set 5: ch1= ch2= ch3= _____
16.If xand yare booleanvariables, do the following two expressions test the same
condition?
x != y
(x || y) && !(x && y)
17.The following ifcondition is made up of three relational expressions:
if(i >= 10 && i <= 20 && i != 16 )
j = 4 ;
If icontains the value 25 when this ifstatement is executed, which relational
expression(s) does the computer evaluate? (Remember that Java uses short-cir-
cuit evaluation.)
- a. If strings cannot be compared using the relational operators in Java, how can
you compare two strings?