Answer:
import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter your statement: ");
String inputCharVect = scan.nextLine();
multiplyString(inputCharVect);
}
public static void multiplyString(String input){
int indexOfWordStart = input.indexOf("t");
int indexOfWordEnd = input.indexOf("s");
String firstString = input.substring(0, indexOfWordStart);
String secondString =input.substring(indexOfWordEnd + 1);
int firstNumber = Integer.parseInt(firstString.trim());
int secondNumber = Integer.parseInt(secondString.trim());
int multResult = firstNumber * secondNumber;
System.out.println(multResult);
}
}
Step-by-step explanation:
The first line of the program is the import statement which import Scanner to allow user input. Then, the user input is assigned to inputCharVect, which is then supplied as arguments to the method multiplyString.
The multiplyString method then extracts the index of 't' and 's' which are the start letter for times, then generate a substring, after which it was assigned to firstNumber and secondNumber. The product of firstNumber and secondNumber is assigned to multResult.