Given string inputString on one line, character inputChar on a second line, and integer strIndex on a third line, output "Match found" if the character at index strIndex of inputString matches inputChar. Otherwise, output "Match not found". End with a newline. Ex: If the input is: warmth m 3 then the output is: Match found Note: Assume the length of string inputString is greater than strIndex. import java.util.Scanner; public class CharMatch { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String inputString; char inputChar; int strIndex; inputString = scnr.nextLine(); inputChar = scnr.next().charAt(0); strIndex = scnr.nextInt(); /* Your code goes here */ } }
Given string inputString on one line, character inputChar on a second line, and integer strIndex on a third line, output "Match found" if the character at index strIndex of inputString matches inputChar. Otherwise, output "Match not found". End with a newline.
Ex: If the input is:
warmth m 3
then the output is:
Match found
Note: Assume the length of string inputString is greater than strIndex.
import java.util.Scanner;
public class CharMatch {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String inputString;
char inputChar;
int strIndex;
inputString = scnr.nextLine();
inputChar = scnr.next().charAt(0);
strIndex = scnr.nextInt();
/* Your code goes here */
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images