PROGRAM FOR COMPARE TWO STRING

This is the programe we can compare the strings,by using the if loop the comparision of string is exactly equale to zero then we will get answer as strings are equal or not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.io.*;
public class ComStr
{
    public static void main(String[] args)throws IOException
    {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Enter First String:");
         String str1 = bf.readLine();
         System.out.println("Enter second String:");
         String str2 = bf.readLine();
         if ( str1.compareTo(str2) ==0 )
            System.err.println("strings are equal");
        else
            System.err.println("strings are not equal");
    }
}

Output:Compare two String

gcdn