Program Menghitung Faktorial dengan Java

Membuat program menghitung faktorial dengan Java.
Jawab :
package DoubleMetHod;
import java.io.*;
public class FaktoriaL {
public static void main(String[] args) {
BufferedReader dataKata =new BufferedReader (new InputStreamReader (System.in));
DataInputStream dataAngka = new DataInputStream (System.in);

int n=0;
int total=1;

System.out.println("Masukkan n faktorial");
try{
n=Integer.parseInt(dataAngka.readLine());
}
catch(IOException e){System.out.println("Terjadi Error");}
System.out.println("Hasil faktorial "+faktorial(n));
}// bagian Akhir 
public static int faktorial(int n){
int hasil=1;
int i=1;

while(i<=n){hasil=hasil*i;i++;
}
return hasil;}
  
}

    Screenshoot :



Hasil :

This entry was posted on Tuesday, 29 September 2015. You can follow any responses to this entry through the RSS 2.0. You can leave a response.

Leave a Reply

Powered by Blogger.