Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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);
  }
}
 
PREVIOUS NEXT
Tagged: #java #product
ADD COMMENT
Topic
Name
2+5 =