java product 1 to n

Solutions on MaxInterview for java product 1 to n by the best coders in the world

showing results for - "java product 1 to n"
Ana
01 May 2017
1public class Main {
2  public static void main(String[] args) {
3    var scanner = new java.util.Scanner(System.in);
4    System.out.print("What is n? ");
5    int n = scanner.nextInt();
6    int product = 1;
7    for (int i = 2; i <= n; ++i) {
8      product *= i;
9    }
10    System.out.println("The product of 1..n is " + product);
11  }
12}
queries leading to this page
java product 1 to njava product 1 to n