Diketahui perhitungan konversi jarak seperti gambar dibawah ini!!
TAHAP 2. Setelah diisi nilainya, mis : 200, maka akan ada permintaan satuannya
Scriptnya seperti dibawah ini...
public static void main(String[] args) {
double nilai = 0;
String konv="";
BufferedReader nila = new BufferedReader(new InputStreamReader(System.in));
BufferedReader kon = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("masukkan nilai : ");
nilai =Integer.parseInt(nila.readLine());
}
catch( IOException e ){
System.out.println("Error!");
}
try {
System.out.println("masukkan satuan : ");
konv =kon.readLine();
System.out.println("=======================");
System.out.println("Berikut Hasilnya :");
System.out.println("=======================");
if("KM".equals(konv)){// proses
System.out.println("MM ="+nilai*1000000); System.out.println("CM ="+nilai*100000); System.out.println("DM ="+nilai*10000); System.out.println("M ="+nilai*1000); System.out.println("DaM ="+nilai*100); System.out.println("HM ="+nilai*10); System.out.println("KM ="+nilai/1); }
else if("KM".equals(konv)){// proses
System.out.println("KM ="+nilai/1);
System.out.println("HM ="+nilai*10);
System.out.println("DaM ="+nilai*100);
System.out.println("M ="+nilai*1000);
System.out.println("DM ="+nilai*10000);
System.out.println("CM ="+nilai*100000);
System.out.println("MM ="+nilai*1000000);
}
else if("HM".equals(konv)){// proses
System.out.println("KM ="+nilai/10);
System.out.println("HM ="+nilai/1);
System.out.println("DaM ="+nilai*10);
System.out.println("M ="+nilai*100);
System.out.println("DM ="+nilai*1000);
System.out.println("CM ="+nilai*10000);
System.out.println("MM ="+nilai*100000);
}
else if("DAM".equals(konv)){// proses
System.out.println("KM ="+nilai/100);
System.out.println("HM ="+nilai/10);
System.out.println("DaM ="+nilai/1);
System.out.println("M ="+nilai*100);
System.out.println("DM ="+nilai*0000);
System.out.println("CM ="+nilai*10000);
System.out.println("MM ="+nilai*100000);
}
else if("M".equals(konv)){// proses
System.out.println("KM ="+nilai/1000);
System.out.println("HM ="+nilai/100);
System.out.println("DaM ="+nilai/10);
System.out.println("M ="+nilai/1);
System.out.println("DM ="+nilai*10);
System.out.println("CM ="+nilai*100);
System.out.println("MM ="+nilai*1000);
}
else if("DM".equals(konv)){// proses
System.out.println("KM ="+nilai/10000);
System.out.println("HM ="+nilai/1000);
System.out.println("DaM ="+nilai/100);
System.out.println("M ="+nilai/10);
System.out.println("DM ="+nilai/1);
System.out.println("CM ="+nilai*10);
System.out.println("MM ="+nilai*100);
}
else if("CM".equals(konv)){// proses
System.out.println("KM ="+nilai/100000);
System.out.println("HM ="+nilai/10000);
System.out.println("DaM ="+nilai/1000);
System.out.println("M ="+nilai/100);
System.out.println("DM ="+nilai/10);
System.out.println("CM ="+nilai/1);
System.out.println("MM ="+nilai*10);
}
else if("MM".equals(konv)){// proses
System.out.println("KM ="+nilai/1000000);
System.out.println("HM ="+nilai/100000);
System.out.println("DaM ="+nilai/10000);
System.out.println("M ="+nilai/1000);
System.out.println("DM ="+nilai/100);
System.out.println("CM ="+nilai/10);
System.out.println("MM ="+nilai/1);
}
}
catch( IOException e ){
System.out.println("Error!");
}
// TODO code application logic here
}}
double nilai = 0;
String konv="";
BufferedReader nila = new BufferedReader(new InputStreamReader(System.in));
BufferedReader kon = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("masukkan nilai : ");
nilai =Integer.parseInt(nila.readLine());
}
catch( IOException e ){
System.out.println("Error!");
}
try {
System.out.println("masukkan satuan : ");
konv =kon.readLine();
System.out.println("=======================");
System.out.println("Berikut Hasilnya :");
System.out.println("=======================");
if("KM".equals(konv)){// proses
System.out.println("MM ="+nilai*1000000); System.out.println("CM ="+nilai*100000); System.out.println("DM ="+nilai*10000); System.out.println("M ="+nilai*1000); System.out.println("DaM ="+nilai*100); System.out.println("HM ="+nilai*10); System.out.println("KM ="+nilai/1); }
else if("KM".equals(konv)){// proses
System.out.println("KM ="+nilai/1);
System.out.println("HM ="+nilai*10);
System.out.println("DaM ="+nilai*100);
System.out.println("M ="+nilai*1000);
System.out.println("DM ="+nilai*10000);
System.out.println("CM ="+nilai*100000);
System.out.println("MM ="+nilai*1000000);
}
else if("HM".equals(konv)){// proses
System.out.println("KM ="+nilai/10);
System.out.println("HM ="+nilai/1);
System.out.println("DaM ="+nilai*10);
System.out.println("M ="+nilai*100);
System.out.println("DM ="+nilai*1000);
System.out.println("CM ="+nilai*10000);
System.out.println("MM ="+nilai*100000);
}
else if("DAM".equals(konv)){// proses
System.out.println("KM ="+nilai/100);
System.out.println("HM ="+nilai/10);
System.out.println("DaM ="+nilai/1);
System.out.println("M ="+nilai*100);
System.out.println("DM ="+nilai*0000);
System.out.println("CM ="+nilai*10000);
System.out.println("MM ="+nilai*100000);
}
else if("M".equals(konv)){// proses
System.out.println("KM ="+nilai/1000);
System.out.println("HM ="+nilai/100);
System.out.println("DaM ="+nilai/10);
System.out.println("M ="+nilai/1);
System.out.println("DM ="+nilai*10);
System.out.println("CM ="+nilai*100);
System.out.println("MM ="+nilai*1000);
}
else if("DM".equals(konv)){// proses
System.out.println("KM ="+nilai/10000);
System.out.println("HM ="+nilai/1000);
System.out.println("DaM ="+nilai/100);
System.out.println("M ="+nilai/10);
System.out.println("DM ="+nilai/1);
System.out.println("CM ="+nilai*10);
System.out.println("MM ="+nilai*100);
}
else if("CM".equals(konv)){// proses
System.out.println("KM ="+nilai/100000);
System.out.println("HM ="+nilai/10000);
System.out.println("DaM ="+nilai/1000);
System.out.println("M ="+nilai/100);
System.out.println("DM ="+nilai/10);
System.out.println("CM ="+nilai/1);
System.out.println("MM ="+nilai*10);
}
else if("MM".equals(konv)){// proses
System.out.println("KM ="+nilai/1000000);
System.out.println("HM ="+nilai/100000);
System.out.println("DaM ="+nilai/10000);
System.out.println("M ="+nilai/1000);
System.out.println("DM ="+nilai/100);
System.out.println("CM ="+nilai/10);
System.out.println("MM ="+nilai/1);
}
}
catch( IOException e ){
System.out.println("Error!");
}
// TODO code application logic here
}}
Dan hasilnya menjadi seperti ini
0 komentar:
Post a Comment