
write a program in java to accept two strings as command line arguments and perform the following operations-: 1) compare the strings 2) check if the first begins with or ends with the second string

Here is an example which accept two strings as command line arguments and perform the following operations-:
1) compare the strings
2) check if the first begins with or ends with the second string
import java.util.*;
class StringExample
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter first string: ");
String str1=input.nextLine();
System.out.print("Enter second string: ");
String str2=input.nextLine();
if(str1.equals(str2)){
System.out.println("Strings are equal!");
}
else{
System.out.println("Strings are not equal!");
}
if(str1.startsWith(str2)){
System.out.println("First string starts with second string");
}
else if(str1.endsWith(str2)){
System.out.println("First string ends with second string");
}
else{
System.out.println("First string neither starts with nor ends with second string");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.