Java Program to Compare two Strings are Equal

Get two strings and check whether both are equal

Sample Input 1:

MARK MAKE

Sample Output 1:

Not Equal

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

public class Hello { public static void main(String args[]) { //Write your code here } }

Program or Solution

				
			
					
//Compare Two Strings Are Equal... 

import java.util.*;

class Program
{
  public static void main(String args[])
 {
     String str1,str2;
     Scanner sc=new Scanner(System.in);

     System.out.println("Enter The String 1:");
     str1=sc.next();

    System.out.println("Enter The String 2:");
    str2=sc.next();

    if(str1.equals(str2))
    {
         System.out.println("Both Are Equal.");
    }

  else
   {
     System.out.println("Not Equal..");
   }

 }
}


			
				
			

Program Explanation

Comments