#507 Multiplication Without the Multiplication Operator
Implement multiplication without using the multiplication operator:
import java.util.*;
public class Main {
public static void main(String[] args) {
System.out.println(multiply(3, 4) + ", Expected 12");
System.out.println(multiply(-2, 3) + ", Expected -6"); // Expected -6
System.out.println(multiply(2, -3) + ", Expected -6"); // Expected -6
System.out.println(multiply(-3, -4) + ", Expected 12"); // Expected 12
System.out.println(multiply(1, 0) + ", Expected 0"); // Expected 0
System.out.println(multiply(0, 0) + ", Expected 0"); // Expected 0
System.out.println(multiply(0, 5) + ", Expected 0"); // Expected 0
System.out.println(multiply(Integer.MAX_VALUE, 1) + ", Expected " + Integer.MAX_VALUE); // Maximum-value check
System.out.println(multiply(Integer.MIN_VALUE, -1) + ", Expected " + Integer.MIN_VALUE); // Minimum-value check
}
public static int multiply(int a, int b) {
// TODO
return a * b; // only for compilation
}
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor