Page 1 of 1

[*Java*] Please help to modify the following code to prompt two numbers from the testers. (Please provide a screenshot o

Posted: Fri May 20, 2022 3:17 pm
by answerhappygod
[*Java*] Please help to modify the following code to
prompt two numbers from the testers. (Please provide a
screenshot of the result. Please do not copy&paste from other
posts. )
(original requirement)
(current code)
public class Main {
public static int product(int n1, int n2) {
return n1 * n2;
}
public static void main(String[] args) {
if (args.length < 2) {

System.out.println("Please run the program by passing two integers
as command line arguments");
} else {
int num1 =
Integer.parseInt(args[0]), num2 = Integer.parseInt(args[1]);
System.out.println("num1
= " + num1);
System.out.println("num2
= " + num2);
int result =
product(num1, num2);
if (result < 0)
{

System.out.println("The result = (-)" + (-1 * result));
} else {

System.out.println("The result = " + result);
}
}
}
}