Write a string compareTo() program

Write a string compareTo() program

Program
import java.util.Scanner;
public class Main
{
    public static void main(String args[])
    {
        String s1,s2;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter String 1 : ");
        s1=sc.nextLine();
        System.out.print("Enter String 2 : ");
        s2=sc.nextLine();
        int n=s1.compareTo(s2);
        if(n==0)
        {
            System.out.println("Both are equal");
        }
        else
        {
            System.out.println("Both are not equal");
        }
    }
}


Output:

Enter String 1 : Sateesh
Enter String 2 : SATEESH
Both are not equal


Strings Handling In Java



More Questions


178 . Write a string compareTo program
179 . Write a string compareToIgnoreCase() Program
180 . Write a string equals program
181 . Write a string equalsIgnoreCase() program
182 . Write a string startsWith() program
183 . Write a string endsWith() program
184 . Write a string indexOf() program
185 . Write a string lastIndexOf() program
186 . Write a String substring() program
187 . Write a string trim() program
188 . Write a StringBuffer insert() program