Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Help. Since first taught, we have understood that multiplication is simply

ID: 3735453 • Letter: N

Question

Need Help.

Since first taught, we have understood that multiplication is simply a form of iterative addition -- that 4 * 3 is shorthand for 4 + 4 + 4. Using the loop control structure, implement an addition alternative to the multiplication operation. The specifics are left to the programmer with the restriction that the answer must not employ Java's language-based implementation for the multiplication operator (ie do not use * when developing the arithmetic solution). A typical interation might look like this:

Enter two positive intergers for multiplication: 5 8
5 * 8 = 40

Notes:

Develop your solution using Java.

Perform appropriate tests to insure user choice meets the criteria. While the Scanner method nextInt() will only accept integer values, test to insure the values entered are greater than zero (0). If the user enters an invalid value, identify the problem with an appropriate error message. Do notperform the arithmetic operation (and do not display a product). The program should display an error message and stop (not attempt to compute the product or prompt for a correct value)

Develop test data and record using an ASCII editor. Match your anticipated responses and the actual responses from the program. The test set should include correct and incorrect data.

After testing with your test data set, record the results as comments at the end of the EC01 source code file.

Submit the source program with the test data set, for credit.

PreviousNext

Explanation / Answer

import java.util.Scanner;

class Solution   // Make a Solution.java file and paste this code
{
   public static void main(String args[])
     {
        int a,b,c=0;
        System.out.println("Enter two numbers for multiplication");
        Scanner sc = new Scanner(System.in);
      try{
        a = sc.nextInt();
        b = sc.nextInt();

       if(a>0 && b>0)
        {
        for(int i=1;i<=b;i++)
                 {
                    c+=a;
                  }
               System.out.println(a + " * " + b + " = " + c);
        }
      else
          System.out.println("Both values should be positive");
         }
      catch(Exception e)
           {
                System.out.println("Enter only positive integers");
           }
    
     }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote