membuat program faktorial rekursif sengan java


import java.io.*;
public class FaktorialRekursif{
public static void main(String[] trs) throws Exception{
BufferedReader qwer = new BufferedReader (new InputStreamReader(System.in));
int a,b;
  
System.out.print ("Inputkan Bilangan = ");
a = Integer.parseInt(qwer.readLine());  
System.out.println(a+"!");
tampilkan(a);
System.out.println("");
System.out.println("hasil = "+(faktorial(a)));
} 
static void tampilkan (int a){
for (int i=a-1; i>0; i--){
for (int j=a; j>=i; j--){
System.out.print (j);
if (j==i)
System.out.print ("");
else 
System.out.print (" x ");}
System.out.println ("");} 
}
static int faktorial(int a){
 if (a==0)
 return(1);
 else
 return(a*faktor(a-1));
}
}




Post a Comment

1 Comments