Write a program in java to demonstrate compareTo() method?

import java.util.Scanner;

class StringCompare

{

                public static void main(String arg[])

                {

                                Scanner in=new Scanner(System.in);

                                System.out.print("Enter First String - ");

                                String s1=in.nextLine();

                                System.out.print("Enter Second String - ");

                                String s2=in.nextLine();

                                System.out.println(s1.compareTo(s2));

                }

}

CompareTo() Method.PNG

, , , , , ,

Leave a Reply