JAVA Define the method printValue() that takes two integer parameters and outputs the product of all negative integers starting with the first and ending with the second parameter. If no negative integers exist, product is 1. End with a newline. The method does not return any value. Ex: If the input is -4 7, then the output is: 24 Note: Negative numbers are less than 0. import java.util.Scanner; public class ValuePrinter { // my code public static void printValue(int n1, int n2) { int i; int product = 1; for (i=n1; i<=n2; ++i) { if (i<0) { product *= i; } else if (i>0) { System.out.println("0"); } } return; } // end my code public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int num1; int num2; num1 = scnr.nextInt(); num2 = scnr.nextInt(); printValue(num1, num2); } }
JAVA
Define the method printValue() that takes two integer parameters and outputs the product of all negative integers starting with the first and ending with the second parameter. If no negative integers exist, product is 1. End with a newline. The method does not return any value.
Ex: If the input is -4 7, then the output is:
24
Note: Negative numbers are less than 0.
import java.util.Scanner;
public class ValuePrinter {
// my code
public static void printValue(int n1, int n2) {
int i;
int product = 1;
for (i=n1; i<=n2; ++i) {
if (i<0) {
product *= i;
}
else if (i>0) {
System.out.println("0");
}
}
return;
}
// end my code
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int num1;
int num2;
num1 = scnr.nextInt();
num2 = scnr.nextInt();
printValue(num1, num2);
}
}

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images









