Question:
Given the string variables name1 , name2 , and name3 , write a fragment of code that assigns the largest value to the variable max (assume all three have already been declared and have been assigned values).
My Answer:
if (name1.compareTo(name2) > 0)
{
if (name1.compareTo(name3) > 0)
max = name1;
}
else if (name2.compareTo(name1) > 0)
{
if (name2.compareTo(name3) > 0)
max = name2;
}
else if (name3.compareTo(name1) > 0)
{
if (name3.compareTo(name2) > 0)
max = name3;
}
2006-09-14
12:17:40
·
2 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design