accept two strings, convert them to lowercase and concatenate both the strings and check whether the concatenated string starts and ends with the same character.
Define a class to accept two strings, convert them to lowercase and concatenate both the
strings and check whether the concatenated string starts and ends with the same character.
display appropriate messages accordingly.
Sample Input:
Input for String1: race
Input for String2: car
Sample Output:
Starts and ends with the same character
import java.util.;
class String_P3
{
public static void main(String[]args)
{
String str1, str2,str;char ch1=' ' , ch2 = ' ';
Scanner sc=new Scanner(System.in);
System.out.println("Enter two strings");
str1=sc.next();/** stores a word/
str2=sc.next();/** stores a word*/
str1=str1.toLowerCase();
str2=str2.toLowerCase();
str = str1.concat(str2);
int str3 = str.length();
for(int i=0;i<=str.length();i++)
{
ch1 = str.charAt(0);
ch2 = str.charAt(str.length()-1);
}
if(ch1==ch2)
System.out.println("Starts and ends with same char");
else
System.out.println("Doesn't starts/ends with same character");
}
}
FOR CODE ,
CLICK : https://onecompiler.com/java/3y4fc5zev (TO FIND OUTPUT)