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).

LANGUAGE: JAVA

CHALLENGE:

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).

SOLUTION:

The Bad News: The content you are trying to access is only available to members.

The Good News: You too can be a member, simply Click Here.

Already a member?

Posted in ,

2 Comments

  1. Shyam Pandey on September 28, 2016 at 2:40 am

    I do not understand how this is correct (but this is what is correct :). what if name3 is the largest one? then, the code assigns name1 to the max before comparing the value of name3, doesn’t it?

    • Jarrod on January 24, 2017 at 1:59 pm

      The last if statement is not indented correctly.

      if (name1.compareTo(name2)>0)max = name1;
      else max = name2;

      if (name3.compareTo(max)>0)max = name3;

Leave a Comment

You must be logged in to post a comment.