Showing posts with label Compare Strings. Show all posts
Showing posts with label Compare Strings. Show all posts

Saturday, 11 October 2014

Compare two String in Java

Structure of the Problem Requirements

In this Problem we will discuss about String built in function. we discuss about compare function in string which is compare the two strings and tell that which string is greater. If first string is greater then its display that first string greater then second. first enter two string and then we compare it.Here is the source code of this problem which help you in better understanding.


SOURCE CODE



import java.util.Scanner;

public class LinkedList
{
   public static voidmain(String args[])
   {
      Stringf_String;
      String s_String;
      Scanner in = new Scanner(System.in);

      System.out.println("Enter First String :");
      f_String = in.nextLine();

      System.out.println("Enter Second String :");
      s_String = in.nextLine();

      if ( f_String.compareTo(s_String) > 0 )
      {
         System.out.println("First String Less Than Second ! ");
      }
      else if ( f_String.compareTo(s_String) < 0 )
      {
          System.out.println("First String Greater Than Second ! ");
      }
      else
      {
         System.out.println("Strings Equal !");
      }
  
   }

}

OUTPUT OF THE PROGRAM


Java String Functions
Compare Strings