3-9 StringCompare

posted Jan 29, 2014, 5:47 AM by Dlovan ismail   [ updated Jan 29, 2014, 5:48 AM by Karwan Jacksi ]
/*This program correctly compares two String objects using
 the equals method.*/

package stringcompare;

public class StringCompare 
{
    public static void main(String[] args) 
    {
            String namel = "Mark", 
                   name2="Mark",
                   name3="Mary";

            // Compare "Mark" and "Mark"
            if (namel.equals(name2))
            {
                System.out.println(namel + " and " + name2+" are the same.");
            }
            else
            {
                 System.out.println(namel + " and " + name2+" are NOT the same.");
            }  

            // Compare "Mark" and "Mary"
            if(namel.equals(name3))
            {
               System.out.println(namel + " and " + name3+" are the same.");
            }
            else
            {
                 System.out.println(namel + " and " + name3+" are NOT the same.");
            }
    }   
}

ċ
StringCompare.java
(1k)
Karwan Jacksi,
Jan 29, 2014, 5:47 AM
Comments