package daa;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class uts_2 {
public static void main (String [] args){
//initialisasi variabel
String angka[]={"0","1","2","3","4","5","6","7","8","9"};
String inputan="";
String cetak="";
char chr=' ';
boolean input_ok=false;
boolean proses_1=false;
boolean proses_2=false;
int m=1;
int hasil=1;
//
//objek buffered reader untuk inputan
InputStreamReader keyreader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(keyreader);
//end objek
while(!input_ok){
try {
System.out.print("Masukkan Nilai = " + "" + "");
inputan=input.readLine();
if (inputan.length()==2)
input_ok=true;
else input_ok=false;
} catch (Exception e) {
}
}
//
for (int i=0;i<angka.length;i++){
chr=inputan.charAt(0);
if (chr==angka[i].charAt(0))
proses_1=true;
}
//
if (proses_1){
chr=inputan.charAt(1);
if (chr=='!')proses_2=true;else proses_2=false;
}
if (proses_1 & proses_2){
m=Integer.valueOf(String.valueOf(inputan.charAt(0)));
for(int i=m;i>=1;i--){
hasil=hasil*i;
if (1<i)
cetak=cetak+i+"! x ";
else
cetak=cetak+i+"! ";
}
System.out.println(m +"! "+"="+" " +" "+cetak );
System.out.println(m +"! "+ "="+" " +hasil+"" );
}
if (!proses_1)
System.out.println("Output ->Bukan Bilangan dan bukan lambang perhitungan Faktorial");
else if (proses_1 & !proses_2)
System.out.println("Output ->Bukan lambang perhitungan Faktorial karena "+ chr);
}
}
Tidak ada komentar:
Posting Komentar