/**
* Do...While untuk mengira nilai faktorial
bagi input integer yang dimasukkan oleh pengguna.
*/
import
java.util.Scanner;
public class
LatihanFactorial {
public static void main(String[] args) {
int n;
int factorial=1;
Scanner input =new Scanner(System.in);
System.out.println("Masukkan nombor
integer : ");
n=input.nextInt();
int i=1;
System.out.println("Pengiraan
faktorial bagi " + n);
do
{
factorial = factorial * i;
System.out.print(i + " x
");
i++;
}
while(i<n);
System.out.print( i + " = " + i*factorial);
}
}Contoh Output:
|
Pages
▼
No comments:
Post a Comment