Ask Question
26 August, 18:39

A multiplication problem is provided as a string using the format 'x times y'. Create a function called MultiplyString to extract the numbers that should be multiplied from a character vector called inputCharVect, and then assign the product to the variable multResult.

+1
Answers (1)
  1. 26 August, 21:59
    0
    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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “A multiplication problem is provided as a string using the format 'x times y'. Create a function called MultiplyString to extract the ...” in 📙 Mathematics if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers