java product 1 to n code example
Example: java product 1 to n
public class Main {
public static void main(String[] args) {
var scanner = new java.util.Scanner(System.in);
System.out.print("What is n? ");
int n = scanner.nextInt();
int product = 1;
for (int i = 2; i <= n; ++i) {
product *= i;
}
System.out.println("The product of 1..n is " + product);
}
}