== vs equals

Lab Java Beginner 10 points

Read two words. Print same if they are equal (case-sensitive), same ignoring case if they differ only in case, otherwise different. Always use equals, never ==.

Input

Two words.

Output

One line.

Example

Input

java java

Output

same
Sample input available Sample output available
Editor
Java

Hints

== compares whether two references point to the same object, not the text.

Solution explanation

Strings read from input are new objects, so == can be false even for equal text. equals compares the characters.

Show solution
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        if (a.equals(b)) {
            System.out.println("same");
        } else if (a.equalsIgnoreCase(b)) {
            System.out.println("same ignoring case");
        } else {
            System.out.println("different");
        }
    }
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD