Question
In this lab, you have to prompt the user to input two integers (say num1 and num2 ). Use a while loop to print out
In this lab, you have to prompt the user to input two integers (say num1 and num2). Use a while loop to print out the product of num1 andnum2. NOTE you will not be using the * operator in your program, rather you will use the fact that multiplication is really just repeated addition in order to calculate the product. (Multiplying 4 by 5 is the same as adding 4 + 4 + 4 + 4 + 4)
Enter two integers: 10 10 10 * 10= 100
JAVA code:
import java.util.Scanner;
public class MultiplyUsingAddition { private int num1; private int num2; public static void main(String[] args) { MultiplyUsingAddition program = new MultiplyUsingAddition(); program.run(); } public void run(){ getInput(); // Call multiplyUsingAdd() int result= //Print the product printOutput(); } public void getInput(){ //Prompt the user to input two integers System.out.println("Enter two integers: "); Scanner scan num1= num2= } public int multiplyUsingAdd(int num1, int num2){ int result= 0; while(){ } return ; } public void printOutput(int result){ System.out.println(num1 + " * " + num2 + " = "); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started