Jumat, 20 Januari 2012

Listing Java Faktorial

package faktorial;
import java.io.DataInputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) {

DataInputStream in = new DataInputStream(System.in);
System.out.println("===========================================");
System.out.println(" PROGRAM FAKTORIAL ");
System.out.println("===========================================");
String username="";
String password="";
String konversi="";
String x="";
String y="";

do {
try {
System.out.print("User Name : ");
username = in.readLine();
} catch (IOException e) {
System.out.println(e);
}
try {
System.out.print("Password : ");
password = in.readLine();
} catch (IOException e) {
System.out.println(e);
}
if ("NAMAMU".equalsIgnoreCase(username)&&"11.11.1111".equalsIgnoreCase(password)) {
System.out.println(" Selamat Datang "+username);


do {
int i=0, kali=1;
try {
System.out.print("Masukan Nilai Faktorial : ");
konversi = in.readLine();
i = Integer.parseInt(konversi);
} catch (IOException e) {
System.out.println(e);
}

do {
if(i>=2) {
System.out.print(i+" * ");
} else {
System.out.print(i+" = ");
}
kali=kali*i;
i+=-1;
} while(i>=1);
System.out.println(kali);
System.out.println("-------------------------------------------");

try {
System.out.print("Apakah Akan Menghitung Lagi? (Y/T) : ");
x=in.readLine();
} catch(IOException e){
System.out.println(e);
}
} while ("Y".equalsIgnoreCase(x));
break;
} else {
try {
System.out.println("Username atau Password salah!");
System.out.print("Masukan User Name Lagi? (Y/T) : ");
y=in.readLine();
} catch(IOException e) {
System.out.println(e);
}
}
} while ("Y".equalsIgnoreCase(y));
System.out.println("-------------------------------------------");
System.out.println(" Terima Kasih ");
System.out.println("-------------------------------------------");
}
}

Tidak ada komentar:

Posting Komentar