In: Computer Science
Write a JAVA program that compares two strings input to see if they are the same?
//importing scanner class to take input from the user
import java.util.Scanner;
//class s
public class s
{
//Main function
public static void main(String args[])
{
//creating object of Scanner class
Scanner input = new Scanner(System.in);
//taking input using scanner class object in string s1 and s2
String s1= input. nextLine();
String s2 = input. nextLine();
//converting both the string into lowercase so that it becomes case
insensitive
//means that it will treat capital and small letters as same
//So the actual content of string is checked and compared
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
//one string is compared to other string using equals function
which checks the content
// of the strings and returns true if both strings matches
otherwise false
//String matches=Prints Both strings are same
//String does not matches=Prints Both strings are not same
if(s1.equals(s2))
System.out.println("Both strings are same");
else
System.out.println("Both strings are not same");
}
}