Mr. Vicky gave a task to his students. He gave two words, but there were some spelling mistakes found. In the first string, "!" denotes the misspelt word. The second string has the correct spelling of the first string. Create a Java application and help the students remove the "!" and replace it with the correctly spelled character.Requirements:- Both the Strings must be of the same length. Otherwise, print "Length of the strings <String1> and <String2> does not match"- Both the Strings must contain only alphabets and '!' symbol. Otherwise, print "<String> contains invalid symbols"- If both the strings contain invalid symbols, print "<String1> and <String2> contains invalid symbols"- The output must have the combined string without any symbolsAssume that space is allowed in between the words and assume that the second string always will have the correct spelt character of the misspelt first string in the respective positions.Note:In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.Ensure to follow the object-oriented specifications provided in the question description.Ensure to provide the names for classes, attributes, and methods as specified in the question description.Adhere to the code template, if provided.Please do not use System.exit(0) to terminate the program. Sample Input/Output 1:Enter the first string!eadEnter the second stringrrrrread Sample Input/Output 2:Enter the first stringF!n! !utEnter the second string!i!d O!!Find OutSample Input/Output 3:Enter the first stringPo**t**nEnter the second String!!si!io!Po**t**n contains invalid symbols Sample Input/Output 4:Enter the first string!a!i!Enter the second stringV*l*dV*l*d contains invalid symbols Sample Input/Output 5:Enter the first stringpr!gra!!i!gEnter the second stringprogrammingprogramming Sample Input/Output 6:Enter the first stringC!rr!sEnter the second string!a!!yLength of the strings C!rr!s and !a!!y does not matchSample Input/Output 7:Enter the first stringC%rr*Enter the second string&a%$yC%rr* and &a%$y contains invalid symbo
Question
Mr. Vicky gave a task to his students. He gave two words, but there were some spelling mistakes found. In the first string, "!" denotes the misspelt word. The second string has the correct spelling of the first string. Create a Java application and help the students remove the "!" and replace it with the correctly spelled character.Requirements:- Both the Strings must be of the same length. Otherwise, print "Length of the strings <String1> and <String2> does not match"- Both the Strings must contain only alphabets and '!' symbol. Otherwise, print "<String> contains invalid symbols"- If both the strings contain invalid symbols, print "<String1> and <String2> contains invalid symbols"- The output must have the combined string without any symbolsAssume that space is allowed in between the words and assume that the second string always will have the correct spelt character of the misspelt first string in the respective positions.Note:In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output.Ensure to follow the object-oriented specifications provided in the question description.Ensure to provide the names for classes, attributes, and methods as specified in the question description.Adhere to the code template, if provided.Please do not use System.exit(0) to terminate the program. Sample Input/Output 1:Enter the first string!eadEnter the second stringrrrrread Sample Input/Output 2:Enter the first stringF!n! !utEnter the second string!i!d O!!Find OutSample Input/Output 3:Enter the first stringPotnEnter the second String!!si!io!Potn contains invalid symbols Sample Input/Output 4:Enter the first string!a!i!Enter the second stringVldVld contains invalid symbols Sample Input/Output 5:Enter the first stringpr!gra!!i!gEnter the second stringprogrammingprogramming Sample Input/Output 6:Enter the first stringC!rr!sEnter the second string!a!!yLength of the strings C!rr!s and !a!!y does not matchSample Input/Output 7:Enter the first stringC%rr*Enter the second string&a%y contains invalid symbo
Solution
Sure, here is a Java solution for the problem:
import java.util.Scanner;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first string");
String str1 = sc.nextLine();
System.out.println("Enter the second string");
String str2 = sc.nextLine();
if (str1.length() != str2.length()) {
System.out.println("Length of the strings " + str1 + " and " + str2 + " does not match");
return;
}
if (!Pattern.matches("[a
Similar Questions
Write a java program to accept a String and the perform the following operations:a) Count the number of words with the first and the last letter being same.
java program to remove special characters from the string
Develop a Java program with a method for comparing two strings.
Problem StatementWrite a program to remove the characters from the first string which are present in the second stringInput FormatGiven two stringsOutput FormatPrint the updated first string
This exercise is to test your understanding of Java Strings. A sample String declaration:String myString = "Hello World!"The elements of a String are called characters. The number of characters in a String is called the length, and it can be retrieved with the String.length() method.Given two strings of lowercase English letters, and , perform the following operations:Sum the lengths of and .Determine if is lexicographically larger than (i.e.: does come before in the dictionary?).Capitalize the first letter in and and print them on a single line, separated by a space.Input FormatThe first line contains a string . The second line contains another string . The strings are comprised of only lowercase English letters.Output FormatThere are three lines of output:For the first line, sum the lengths of and .For the second line, write Yes if is lexicographically greater than otherwise print No instead.For the third line, capitalize the first letter in both and and print them on a single line, separated by a space.Sample Input 0hellojavaSample Output 09NoHello JavaExplanation 0String is "hello" and is "java". has a length of , and has a length of ; the sum of their lengths is .When sorted alphabetically/lexicographically, "hello" precedes "java"; therefore, is not greater than and the answer is No.When you capitalize the first letter of both and and then print them separated by a space, you get "Hello Java".
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.