TQC+ JAVA 305 迴圈階層計算
import java.util.Scanner;
public class JPA03 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
test();
test();
test();
}
public static void test() {
System.out.print("Please enter one value:");
int n=keyboard.nextInt();
int i,sum=1;
if(n<1 ||n>10)
System.out.println("Error, the value is out of range.");
else{
for(i=1;i<=n;i++){
sum *=i;
}
System.out.println(n+"!:"+sum);
}
}
}
沒有留言:
張貼留言