Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to compare Strings by compring successive corresponding characters, starting with the first character in each String

Posted By: Adrian Baker     Category: Java     Views: 6179

A Java Program to compare Strings by compring successive corresponding characters, starting with the first character in each String.

Code for Program to compare Strings by compring successive corresponding characters, starting with the first character in each String in Java

publicclass JAVA_048
 {
    publicstaticvoid main(String[] args)
    {
       String String1="A";
       String String2="To";
       String String3="Z";

       System.out.println("String1 : " + String1);
       System.out.println("String2 : " + String2);
       System.out.println("String3 : " + String3);

       if(String1.compareTo(String3)<0)
          System.out.println("String1 is less than String3");

       else
       {
          if(String1.compareTo(String3)>0)
             System.out.println("String1 is greater than String3");

          else
             System.out.println("String1 is equal to String3");
       }

       if(String2.compareTo(String1)<0)
          System.out.println("String1 is less than String1");

       else
       {
          if(String2.compareTo(String1)>0)
             System.out.println("String2 is greater than String1");

          else
             System.out.println("String2 is equal to String1");
       }
    }
 }
  
Share: 



Adrian Baker
Adrian Baker author of Program to compare Strings by compring successive corresponding characters, starting with the first character in each String is from Houston, United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!