輸入一個大於1的數,求1和這個數的階乘用三種循環語句 for ,while , do...while
Java 版本的來了。
int result = 1;
for(int i =1;i<=number;i++) {
result*=i
}
System.out.println("Result=" + result);
int result = 1;
int counter=1;
while(counter<=number){
result*=counter;
counter++;
}
System.out.println("Result=" + result);
int result = 1;
int counter = 1;
do{
result*=counter;
counter++;
}while(counter<=number);