3-10 StringCompareTo

posted Jan 29, 2014, 6:03 AM by Dlovan ismail   [ updated Jan 29, 2014, 6:03 AM by Karwan Jacksi ]
/*
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);
            }
    }   
}

ċ
StringCompareTo.java
(1k)
Karwan Jacksi,
Jan 29, 2014, 6:03 AM
Comments