Write an applacation that demonstrates that when two identical names are compare
ID: 3628873 • Letter: W
Question
Write an applacation that demonstrates that when two identical names are compared and the case differs, the equals() method returns false, but the equalsIgnore() method returns true.This is what I have . I just need someone to check it. I have no errors.
[code]
package week_4;
/**
*
* @author me
*/
import java.util.Scanner;
public class CompareCase
{
public static void main(String[] args)
{
String aName = "Dana";
String anotherName;
Scanner input = new Scanner(System.in);
System.out.print("Enter your name > ");
anotherName = input.nextLine();
if(aName.equals(anotherName)) {
System.out.println(aName + " equals " + anotherName);
}
else if(aName.equalsIgnoreCase(anotherName)) {
System.out.println(aName + " equals with ignore case " + anotherName); }
else {
System.out.println(aName + " is not equal to " + anotherName); }
}
}
[code]
Thanks
Explanation / Answer
please rate - thanks
your almost okay.
no matter what you should have a response for ignore case and for equals. I would also input both names
/**
*
* @author me
*/
import java.util.Scanner;
public class CompareCase
{
public static void main(String[] args)
{
String aName ;
String anotherName;
Scanner input = new Scanner(System.in);
System.out.print("Enter your name > ");
aName = input.nextLine();
System.out.print("Enter your name again > ");
anotherName = input.nextLine();
if(aName.equals(anotherName))
System.out.println(aName + " equals " + anotherName+" with equals");
else
System.out.println(aName + " doesn't equal " + anotherName+" with equals");
if(aName.equalsIgnoreCase(anotherName)) {
System.out.println(aName + " equals with ignore case " + anotherName); }
else {
System.out.println(aName + " is not equal to " + anotherName+" with ignore case"); }
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.