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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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);
}
}
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply