Here you can find the source of factorial(int n)
public static long factorial(int n)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 University of Illinois at Urbana-Champaign and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*www . j a v a 2 s . c om*/ * UIUC - Initial API and implementation *******************************************************************************/ public class Main { /** @return the <i>n!</i> */ public static long factorial(int n) { if (n < 0) throw new IllegalArgumentException(); if (n < 2) return 1; long result = 1; for (int i = n; i >= 2; i--) result *= i; return result; } }