Program Java Memilih Nilai Faktorial
Berikut aku akan memperlihatkan pola mengenai Membuat Program Menentukan Nilai Fatorial memakai Bahasa Pemograman Java. Contoh Menghitung Nilai Fatorial dari 5! kesudahannya yaitu 120. Contoh Script yaitu sebagai berikut.
/*Program LuasPersegiPanjang
Created by : Marvel Ricky Polii
*/
import java.util.Scanner;
class Faktorial{
public static void main(String[]args){
int bil, n, n1, n2, n3, n4, n5, n6, n7;
long hasil, jum;
Scanner scan=new Scanner(System.in);
System.out.println("==========================");
System.out.println(" Mencari Nilai Faktorial! ");
System.out.println("==========================");
System.out.println();
System.out.print("Masukan Angka :");
while (!scan.hasNextDouble()) { // mengusut jikalau terjadi kesalahan masukkan
System.out.print("Tolong Masukkan Angka :"); // yang tidak sesuai format
scan.nextLine();
}
n=scan.nextInt();
n1=n-1;
n2=n1-1;
n3=n2-1;
n4=n3-1;
n5=n*n1;
n6=n5*n2;
n7=n6*n3;
System.out.println(" Step1 : " + n+"*"+1);
System.out.println(" Step2 : " + n5+"*"+n2);
System.out.println(" Step3 : " + n6+"*"+n3);
System.out.println(" Step4 : " + n7+"*"+n4);
System.out.println();
hasil=1;
for (bil = f; bil>=1; bil--)
hasil=hasil*bil;
System.out.println("Faktorial : " + n + "! = " + hasil);
}
}
/*Program LuasPersegiPanjang
Created by : Marvel Ricky Polii
*/
import java.util.Scanner;
class Faktorial{
public static void main(String[]args){
int bil, n, n1, n2, n3, n4, n5, n6, n7;
long hasil, jum;
Scanner scan=new Scanner(System.in);
System.out.println("==========================");
System.out.println(" Mencari Nilai Faktorial! ");
System.out.println("==========================");
System.out.println();
System.out.print("Masukan Angka :");
while (!scan.hasNextDouble()) { // mengusut jikalau terjadi kesalahan masukkan
System.out.print("Tolong Masukkan Angka :"); // yang tidak sesuai format
scan.nextLine();
}
n=scan.nextInt();
n1=n-1;
n2=n1-1;
n3=n2-1;
n4=n3-1;
n5=n*n1;
n6=n5*n2;
n7=n6*n3;
System.out.println(" Step1 : " + n+"*"+1);
System.out.println(" Step2 : " + n5+"*"+n2);
System.out.println(" Step3 : " + n6+"*"+n3);
System.out.println(" Step4 : " + n7+"*"+n4);
System.out.println();
hasil=1;
for (bil = f; bil>=1; bil--)
hasil=hasil*bil;
System.out.println("Faktorial : " + n + "! = " + hasil);
}
}
Semoga Bermanfaat