12 September 2018

Java program to compare two strings

//Java program to compare two strings
import java.util.*;
class string1
   {
  public static void main(String args[])
    {
    String a="Welcome to Java";
    String b="Welcome to C++";
    String c="Welcome to Java";
   
    //comparing strings a and b
    if(a.equals(b))
      System.out.println("\t "+a+" and "+b+" are equal ");
    else
      System.out.println("\t "+a+" and "+b+" are not equal");
   
    //comparing strings a and c
    if(a.equals(c))
      System.out.println("\t "+a+" and "+c+" are equal ");
    else
      System.out.println("\t "+a+" and "+c+" are equal ");
    }
 }
Output will be similar to this :











A similar program to this :

Java Program for concatenation of two strings

No comments:

Post a Comment

To convert from Upper case to lowercase(A to a)

//converting from Upper to lower(A to a) import java.util.*; class case { public static void main(String args[]) { System.out.pr...