Menghitung Nilai Faktorial dengan Java

Untuk Menghitung nilai faktorial dengan menggunakan java pastikan java anda 
telah di set path sebelum di kompiler.
copy sourcecode berikut dan pastekan di notepad dan simpan dengan nama sesuai 
dengan keinginan dan file harus berekstensi .java*
class faktorial {
public static void main (String args []) throws Exception{
InputStreamReader key = new InputStreamReader (System.in);
BufferedReader input = new BufferedReader (key);
String n;
int i,j,k=1;
System.out.print ("==============================");
System.out.print("\n");
System.out.println ("NAMA: RIVALRY KRISTIANTO HONDRO");
System.out.println ("NPM : 0811199");
System.out.println ("Tema: Menghitung Bilangan Faktorial ");
System.out.print ("==============================");
System.out.println(" ");
System.out.print("\n");
System.out.print ("Masukkan Nilai Faktorial = ");
n=input.readLine();
j=Integer.parseInt(n);
System.out.print(j+"!= ");
for (i=j; i>=1; i--){
System.out.print(i);
if (i>1)
System.out.print("x");
k=k*i;}
System.out.print("\n");
System.out.print(j+"!= "+k);}}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s