3-10 StringCompareTo

Post date: Jan 29, 2014 2:03:07 PM

/*

This program compares two String objects using

the conpareTo method.

*/

package stringcompareto;

public class StringCompareTo 

{

    public static void main(String[] args) 

    {

            String namel = "Mary",

                   name2 = "Mark";

            // Compare "Mary" and "Mark"

            if (namel.compareTo(name2) < 0)

            {

                System.out.println(namel+" is less than " + name2);

            }

            else if (namel.compareTo(name2) == 0)

            {

                System.out.println(namel+" is equal to " + name2);

            }

            else if (namel.compareTo(name2) > 0)

            {

                System.out.println(namel+" is greater than " + name2);

            }

    }   

}