Q:

Java Program to Compare two Strings

0

Program to Compare two Strings.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
 
class demo1
{
   public static void main(String args[])
   {
      String s1, s2;
      Scanner in = new Scanner(System.in);
 
      System.out.println("Enter the first string");
      s1 = in.nextLine();
 
      System.out.println("Enter the second string");
      s2 = in.nextLine();
 
      if (s1.compareTo(s2) > 0)
         System.out.println("The first string is greater than the second.");
      else if (s1.compareTo(s2) < 0)
         System.out.println("The first string is smaller than the second.");
      else   
         System.out.println("Both the strings are equal.");
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now