Kelas = X-TKJ 1 / 33
Source Code Program Java Function:
Link Download Function = Di Sini
import java.util.Scanner;
public class nggarapDewe{
public static void main(String[] args) {
Scanner masukan = new Scanner(System.in);
int pilihan=9;
do {
try {
System.out.println("\t+-------------------------------+");
System.out.println("\t|---Menu Konversi Satuan Jarak--|\t");
System.out.println("\t+-------------------------------+");
System.out.println("\t|\t|1) KM \t\t\t|");
System.out.println("\t|\t|2) HM \t\t\t|");
System.out.println("\t|\t|3) DAM \t\t|");
System.out.println("\t|\t|4) M \t\t\t|");
System.out.println("\t|\t|5) DM \t\t\t|");
System.out.println("\t|\t|6) CM \t\t\t|");
System.out.println("\t|\t|7) MM \t\t\t|");
System.out.println("\t|\t|8) Keluar\t\t|");
System.out.println("\t+-------------------------------+");
System.out.print("\t|Masukkan Pilihan Anda = ");
pilihan=masukan.nextInt();
switch(pilihan){
case 1 : km(); break;
case 2 : hm(); break;
case 3 : dam(); break;
case 4 : m(); break;
case 5 : dm(); break;
case 6 : cm(); break;
case 7 : mm(); break;
case 8 : break;
default :
System.out.println("\t|!!!Menu Yang Anda Plih Tidak Tersedia!!!\t");
}
}
catch(Exception e)
{
System.err.println("\t|!!!Hanya Boleh angka!!!\t");
masukan.nextLine();
}
} while(pilihan != 8);
}
private static void km() {
Scanner masukan = new Scanner(System.in);
int pilihan=7;
Float km, hm, dam, m, dm, cm, mm;
for (String a = "Y"; a.equals("Y") || a.equals("y");) {
System.out.println("\t+-------------------------------+");
System.out.println("\t|-----------Menu KM-------------|\t");
System.out.println("\t|\t|1)KM ke HM \t\t|");
System.out.println("\t|\t|2)KM ke DAM \t\t|");
System.out.println("\t|\t|3)KM ke M \t\t|");
System.out.println("\t|\t|4)KM ke DM \t\t|");
System.out.println("\t|\t|5)KM ke CM \t\t|");
System.out.println("\t|\t|6)KM ke MM \t\t|");
System.out.println("\t|\t|7)Keluar \t\t|");
System.out.println("\t+-------------------------------+");
System.out.print("\t|Masukkan Pilihan Anda = ");
pilihan=masukan.nextInt();
System.out.println("\t+-------------------------------+");
if(pilihan==1){
do{
System.out.print("\t|Masukkan jarak KM = "); km = masukan.nextFloat();
if(km<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(km<0);
hm = km * 10;
System.out.println("\t|\t"+km +" KM = " +hm+ " HM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==2){
do{
System.out.print("\t|Masukkan jarak KM = "); km = masukan.nextFloat();
if(km<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(km<0);
dam = km * 100;
System.out.println("\t|\t"+km +" KM = " +dam+ " DAM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==3){
do{
System.out.print("\t|Masukkan jarak KM = "); km = masukan.nextFloat();
if(km<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(km<0);
m = km * 1000;
System.out.println("\t|\t"+km +" KM = " +m+ " M");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==4){
do{
System.out.print("\t|Masukkan jarak KM = "); km = masukan.nextFloat();
if(km<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(km<0);
dm = km * 10000;
System.out.println("\t|\t"+km +" KM = " +dm+ " DM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==5){
do{
System.out.print("\t|Masukkan jarak KM = "); km = masukan.nextFloat();
if(km<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(km<0);
cm = km * 100000;
System.out.println("\t|\t"+km +" KM = " +cm+ " CM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==6){
do{
System.out.print("\t|Masukkan jarak KM = "); km = masukan.nextFloat();
if(km<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(km<0);
mm = km * 1000000;
System.out.println("\t|\t"+km +" KM = " +mm+ " MM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==7){
} else { System.out.println("\t|Maaf Nomor Yang anda masukkan tidak tersedia");
}System.out.println("\t|Sebelum keluar dari menu KM");
System.out.print("\t|Anda ingin mencoba menu KM lagi (Y/N) : ");
a = masukan.next();}}
private static void hm() {
Scanner masukan = new Scanner(System.in);
Float km, hm, dam, m, dm, cm, mm;
int pilihan=7;
for (String a = "Y"; a.equals("Y") || a.equals("y");) {
System.out.println("\t+-------------------------------+");
System.out.println("\t|-----------Menu HM-------------|\t");
System.out.println("\t|\t|1)HM ke KM \t\t|");
System.out.println("\t|\t|2)HM ke DAM \t\t|");
System.out.println("\t|\t|3)HM ke M \t\t|");
System.out.println("\t|\t|4)HM ke DM \t\t|");
System.out.println("\t|\t|5)HM ke CM \t\t|");
System.out.println("\t|\t|6)HM ke MM \t\t|");
System.out.println("\t|\t|7)Keluar \t\t|");
System.out.println("\t+-------------------------------+");
System.out.print("\t|Masukkan Pilihan Anda = ");
pilihan=masukan.nextInt();
System.out.println("\t+-------------------------------+");
if(pilihan==1){
do{
System.out.print("\t|Masukkan jarak HM = "); hm = masukan.nextFloat();
if(hm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(hm<0);
km = hm / 10;
System.out.println("\t|\t"+hm +" HM = " +km+ " KM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==2){
do{
System.out.print("\t|Masukkan jarak HM = "); hm = masukan.nextFloat();
if(hm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(hm<0);
dam = hm * 10;
System.out.println("\t|\t"+hm +" HM = " +dam+ " DAM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==3){
do{
System.out.print("\t|Masukkan jarak HM = "); hm = masukan.nextFloat();
if(hm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(hm<0);
m = hm * 100;
System.out.println("\t|\t"+hm +" HM = " +m+ " KM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==4){
do{
System.out.print("\t|Masukkan jarak HM = "); hm = masukan.nextFloat();
if(hm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(hm<0);
dm = hm * 1000;
System.out.println("\t|\t"+hm +" HM = " +dm+ " DM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==5){
do{
System.out.print("\t|Masukkan jarak HM = "); hm = masukan.nextFloat();
if(hm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(hm<0);
cm = hm * 10000;
System.out.println("\t|\t"+hm +" HM = " +cm+ " CM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==6){
do{
System.out.print("\t|Masukkan jarak HM = "); hm = masukan.nextFloat();
if(hm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(hm<0);
mm = hm * 100000;
System.out.println("\t|\t"+hm +" HM = " +mm+ " MM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==7) {
} else { System.out.println("\t|Maaf Nomor Yang anda masukkan tidak tersedia");
}System.out.println("\t|Sebelum keluar dari menu HM");
System.out.print("\t|Anda ingin mencoba menu HM lagi (Y/N) : ");
a = masukan.next();}}
private static void dam() {
Scanner masukan = new Scanner(System.in);
Float km, hm, dam, m, dm, cm, mm;
int pilihan=7;
for (String a = "Y"; a.equals("Y") || a.equals("y");) {
System.out.println("\t+-------------------------------+");
System.out.println("\t|-----------Menu DAM------------|\t");
System.out.println("\t|\t|1)DAM ke KM \t\t|");
System.out.println("\t|\t|2)DAM ke HM \t\t|");
System.out.println("\t|\t|3)DAM ke M \t\t|");
System.out.println("\t|\t|4)DAM ke DM \t\t|");
System.out.println("\t|\t|5)DAM ke CM \t\t|");
System.out.println("\t|\t|6)DAM ke MM \t\t|");
System.out.println("\t|\t|7)Keluar \t\t|");
System.out.println("\t+-------------------------------+");
System.out.print("\t|Masukkan Pilihan Anda = ");
pilihan=masukan.nextInt();
System.out.println("\t+-------------------------------+");
if(pilihan==1){
do{
System.out.print("\t|Masukkan jarak DAM = "); dam = masukan.nextFloat();
if(dam<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dam<0);
km = dam / 100;
System.out.println("\t|\t"+dam +" DAM = " +km+ " KM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==2){
do{
System.out.print("\t|Masukkan jarak DAM = "); dam = masukan.nextFloat();
if(dam<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dam<0);
hm = dam / 10;
System.out.println("\t|\t"+dam +" DAM = " +hm+ " HM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==3){
do{
System.out.print("\t|Masukkan jarak DAM = "); dam = masukan.nextFloat();
if(dam<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dam<0);
m = dam * 10;
System.out.println("\t|\t"+dam +" DAM = " +m+ " M");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==4){
do{
System.out.print("\t|Masukkan jarak DAM = "); dam = masukan.nextFloat();
if(dam<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dam<0);
dm = dam * 100;
System.out.println("\t|\t"+dam +" DAM = " +dm+ " DM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==5){
do{
System.out.print("\t|Masukkan jarak DAM = "); dam = masukan.nextFloat();
if(dam<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dam<0);
cm = dam * 1000;
System.out.println("\t|\t"+dam +" DAM = " +cm+ " CM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==6){
do{
System.out.print("\t|Masukkan jarak DAM = "); dam = masukan.nextFloat();
if(dam<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dam<0);
mm = dam * 10000;
System.out.println("\t|\t"+dam +" DAM = " +mm+ " MM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==7) {
} else { System.out.println("\t|Maaf Nomor Yang anda masukkan tidak tersedia");
}System.out.println("\t|Sebelum keluar dari menu DAM");
System.out.print("\t|Anda ingin mencoba menu DAM lagi (Y/N) : ");
a = masukan.next();}}
private static void m() {
Scanner masukan = new Scanner(System.in);
Float km, hm, dam, m, dm, cm, mm;
int pilihan=7;
for (String a = "Y"; a.equals("Y") || a.equals("y");) {
System.out.println("\t+-------------------------------+");
System.out.println("\t|------------Menu M-------------|\t");
System.out.println("\t|\t|1)M ke KM \t\t|");
System.out.println("\t|\t|2)M ke HM \t\t|");
System.out.println("\t|\t|3)M ke DAM \t\t|");
System.out.println("\t|\t|4)M ke DM \t\t|");
System.out.println("\t|\t|5)M ke CM \t\t|");
System.out.println("\t|\t|6)M ke MM \t\t|");
System.out.println("\t|\t|7)Keluar \t\t|");
System.out.println("\t+-------------------------------+");
System.out.print("\t|Masukkan Pilihan Anda = ");
pilihan=masukan.nextInt();
System.out.println("\t+-------------------------------+");
if(pilihan==1){
do{
System.out.print("\t|Masukkan jarak M = "); m = masukan.nextFloat();
if(m<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(m<0);
km = m / 1000;
System.out.println("\t|\t"+m +" M = " +km+ " KM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==2){
do{
System.out.print("\t|Masukkan jarak M = "); m = masukan.nextFloat();
if(m<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(m<0);
hm = m / 100;
System.out.println("\t|\t"+m +" M = " +hm+ " HM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==3){
do{
System.out.print("\t|Masukkan jarak M = "); m = masukan.nextFloat();
if(m<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(m<0);
dam = m / 10;
System.out.println("\t|\t"+m +" M = " +dam+ " DAM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==4){
do{
System.out.print("\t|Masukkan jarak M = "); m = masukan.nextFloat();
if(m<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(m<0);
dm = m * 10;
System.out.println("\t|\t"+m +" M = " +dm+ " DM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==5){
do{
System.out.print("\t|Masukkan jarak M = "); m = masukan.nextFloat();
if(m<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(m<0);
cm = m * 100;
System.out.println("\t|\t"+m +" M = " +cm+ " CM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==6){
do{
System.out.print("\t|Masukkan jarak M = "); m = masukan.nextFloat();
if(m<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(m<0);
mm = m * 1000;
System.out.println("\t|\t"+m +" M = " +mm+ " MM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==7) {
} else { System.out.println("\t|Maaf Nomor Yang anda masukkan tidak tersedia");
}System.out.println("\t|Sebelum keluar dari menu M");
System.out.print("\t|Anda ingin mencoba menu M lagi (Y/N) : ");
a = masukan.next();}}
private static void dm() {
Scanner masukan = new Scanner(System.in);
Float km, hm, dam, m, dm, cm, mm;
int pilihan=7;
for (String a = "Y"; a.equals("Y") || a.equals("y");) {
System.out.println("\t+-------------------------------+");
System.out.println("\t|-----------Menu DM-------------|\t");
System.out.println("\t|\t|1)DM ke KM \t\t|");
System.out.println("\t|\t|2)DM ke HM \t\t|");
System.out.println("\t|\t|3)DM ke DAM \t\t|");
System.out.println("\t|\t|4)DM ke M \t\t|");
System.out.println("\t|\t|5)DM ke CM \t\t|");
System.out.println("\t|\t|6)DM ke MM \t\t|");
System.out.println("\t|\t|7)Keluar \t\t|");
System.out.println("\t+-------------------------------+");
System.out.print("\t|Masukkan Pilihan Anda = ");
pilihan=masukan.nextInt();
System.out.println("\t+-------------------------------+");
if(pilihan==1){
do{
System.out.print("\t|Masukkan jarak DM = "); dm = masukan.nextFloat();
if(dm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dm<0);
km = dm / 10000;
System.out.println("\t|\t"+dm +" DM = " +km+ " KM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==2){
do{
System.out.print("\t|Masukkan jarak DM = "); dm = masukan.nextFloat();
if(dm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dm<0);
hm = dm / 1000;
System.out.println("\t|\t"+dm +" DM = " +hm+ " HM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==3){
do{
System.out.print("\t|Masukkan jarak DM = "); dm = masukan.nextFloat();
if(dm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dm<0);
dam = dm / 100;
System.out.println("\t|\t"+dm +" DM = " +dam+ " DAM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==4){
do{
System.out.print("\t|Masukkan jarak DM = "); dm = masukan.nextFloat();
if(dm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dm<0);
m = dm / 10;
System.out.println("\t|\t"+dm +" DM = " +m+ " M");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==5){
do{
System.out.print("\t|Masukkan jarak DM = "); dm = masukan.nextFloat();
if(dm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dm<0);
cm = dm * 10;
System.out.println("\t|\t"+dm +" DM = " +cm+ " CM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==6){
do{
System.out.print("\t|Masukkan jarak DM = "); dm = masukan.nextFloat();
if(dm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(dm<0);
mm = dm * 100;
System.out.println("\t|\t"+dm +" DM = " +mm+ " MM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==7) {
} else { System.out.println("\t|Maaf Nomor Yang anda masukkan tidak tersedia");
}System.out.println("\t|Sebelum keluar dari menu DM");
System.out.print("\t|Anda ingin mencoba menu DM lagi (Y/N) : ");
a = masukan.next();}}
private static void cm() {
Scanner masukan = new Scanner(System.in);
Float km, hm, dam, m, dm, cm, mm;
int pilihan=7;
for (String a = "Y"; a.equals("Y") || a.equals("y");) {
System.out.println("\t+-------------------------------+");
System.out.println("\t|-----------Menu CM-------------|\t");
System.out.println("\t|\t|1)CM ke KM \t\t|");
System.out.println("\t|\t|2)CM ke HM \t\t|");
System.out.println("\t|\t|3)CM ke DAM \t\t|");
System.out.println("\t|\t|4)CM ke M \t\t|");
System.out.println("\t|\t|5)CM ke DM \t\t|");
System.out.println("\t|\t|6)CM ke MM \t\t|");
System.out.println("\t|\t|7)Keluar \t\t|");
System.out.println("\t+-------------------------------+");
System.out.print("\t|Masukkan Pilihan Anda = ");
pilihan=masukan.nextInt();
System.out.println("\t+-------------------------------+");
if(pilihan==1){
do{
System.out.print("\t|Masukkan jarak CM = "); cm = masukan.nextFloat();
if(cm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(cm<0);
km = cm / 100000;
System.out.println("\t|\t"+cm +" CM = " +km+ " KM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==2){
do{
System.out.print("\t|Masukkan jarak CM = "); cm = masukan.nextFloat();
if(cm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(cm<0);
hm = cm / 10000;
System.out.println("\t|\t"+cm +" CM = " +hm+ " HM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==3){
do{
System.out.print("\t|Masukkan jarak CM = "); cm = masukan.nextFloat();
if(cm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(cm<0);
dam = cm / 1000;
System.out.println("\t|\t"+cm +" CM = " +dam+ " DAM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==4){
do{
System.out.print("\t|Masukkan jarak CM = "); cm = masukan.nextFloat();
if(cm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(cm<0);
m = cm / 100;
System.out.println("\t|\t"+cm +" CM = " +m+ " M");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==5){
do{
System.out.print("\t|Masukkan jarak CM = "); cm = masukan.nextFloat();
if(cm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(cm<0);
dm = cm / 10;
System.out.println("\t|\t"+cm +" CM = " +dm+ " DM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==6){
do{
System.out.print("\t|Masukkan jarak CM = "); cm = masukan.nextFloat();
if(cm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(cm<0);
mm = cm * 10;
System.out.println("\t|\t"+cm +" CM = " +mm+ " MM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==7) {
} else { System.out.println("\t|Maaf Nomor Yang anda masukkan tidak tersedia");
}System.out.println("\t|Sebelum keluar dari menu CM");
System.out.print("\t|Anda ingin mencoba menu CM lagi (Y/N) : ");
a = masukan.next();}}
private static void mm() {
Scanner masukan = new Scanner(System.in);
Float km, hm, dam, m, dm, cm, mm;
int pilihan=7;
for (String a = "Y"; a.equals("Y") || a.equals("y");) {
System.out.println("\t+-------------------------------+");
System.out.println("\t|-----------Menu MM-------------|\t");
System.out.println("\t|\t|1)MM ke KM \t\t|");
System.out.println("\t|\t|2)MM ke HM \t\t|");
System.out.println("\t|\t|3)MM ke DAM \t\t|");
System.out.println("\t|\t|4)MM ke M \t\t|");
System.out.println("\t|\t|5)MM ke DM \t\t|");
System.out.println("\t|\t|6)MM ke CM \t\t|");
System.out.println("\t|\t|7)Keluar \t\t|");
System.out.println("\t+-------------------------------+");
System.out.print("\t|Masukkan Pilihan Anda = ");
pilihan=masukan.nextInt();
System.out.println("\t+-------------------------------+");
if(pilihan==1){
do{
System.out.print("\t|Masukkan jarak MM = "); mm = masukan.nextFloat();
if(mm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(mm<0);
km = mm / 1000000;
System.out.println("\t|\t"+mm +" MM = " +km+ " KM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==2){
do{
System.out.print("\t|Masukkan jarak MM = "); mm = masukan.nextFloat();
if(mm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(mm<0);
hm = mm / 100000;
System.out.println("\t|\t"+mm +" MM = " +hm+ " HMM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==3){
do{
System.out.print("\t|Masukkan jarak MM = "); mm = masukan.nextFloat();
if(mm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(mm<0);
dam = mm / 10000;
System.out.println("\t|\t"+mm +" MM = " +dam+ " DAM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==4){
do{
System.out.print("\t|Masukkan jarak MM = "); mm = masukan.nextFloat();
if(mm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(mm<0);
m = mm / 1000;
System.out.println("\t|\t"+mm +" MM = " +m+ " M");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==5){
do{
System.out.print("\t|Masukkan jarak MM = "); mm = masukan.nextFloat();
if(mm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(mm<0);
dm = mm / 100;
System.out.println("\t|\t"+mm +" MM = " +dm+ " DM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==6){
do{
System.out.print("\t|Masukkan jarak MM = "); mm = masukan.nextFloat();
if(mm<0){
System.out.println("\t|!!Maaf Bilangan Harus Positif!!");
}}while(mm<0);
cm = mm / 10;
System.out.println("\t|\t"+mm +" MM = " +cm+ " CM");
System.out.println("\t+++++++++++++++++++++++++++++++++");
} else if(pilihan==7) {
} else { System.out.println("\t|Maaf Nomor Yang anda masukkan tidak tersedia");
}System.out.println("\t|Sebelum keluar dari menu MM");
System.out.print("\t|Anda ingin mencoba menu MM lagi (Y/N) : ");
a = masukan.next();}}
}
Output Program:
=) Jika memasukkan huruf
=) Jika memasukkan angka 1 lalu memilih menu 7 yang berarti keluar serta memilih "n" untuk kembali ke menu awal
=) Jika memasukkan angka 1 lalu memilih menu 1 dan memasukkan angka yang negatif
=) Jika memasukkan angka selain yang tertera pada menu
=) Jika memasukkan pilihan yang benar semuanya
Source Code Program Java Array:
public class array {
public static void main(String[] args){
System.out.print("Input Jumlah atau Panjang Array = ");
Scanner input = new Scanner(System.in);
int w = input.nextInt();
int array[] = new int[w];
int hasil = 0;
for(int a = 0; a<array.length; a++){
System.out.print("Masukan Angka :");
array[a] = input.nextInt();
hasil = hasil + array[a];
}
for (int i = 0; i <w; i++){
}
System.out.println("Hasil Ditambah = "+hasil);
System.out.println("Setelah Ditambah lalu dikali");
System.out.print("Masukkan Angka = ");
int b = input.nextInt();
System.out.println("Hasil = "+(hasil * b));
int jumlah = +hasil * +b;
System.out.println("Setelah Dikali lalu dibagi");
System.out.print("Masukkan Angka = ");
int c = input.nextInt();
System.out.println("Hasil = "+(jumlah / c));
int jumlahh = +jumlah / +c;
System.out.println("Setelah Dibagi lalu dikurangi");
System.out.print("Masukkan Angka = ");
int d = input.nextInt();
System.out.println("Hasil Akhir = " +(jumlahh - d));
}
}
Output Program:
=) Jika memasukkan huruf
=) Jika memasukkan dengan sesuai
0 komentar:
Posting Komentar