Selamat pagi, kali ini saya akan membagikan cara menentukan hari dan pasaran jawa dengan pemrograman java.
Dibawah ini adalah condingnya:
import java.util.Scanner;
public class JavaDateSystem {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Hari dalam seminggu\n"
+ " [0] Minggu\n"
+ " [1] Senin\n"
+ " [2] Selasa\n"
+ " [3] Rabu\n"
+ " [4] Kamis\n"
+ " [5] Jumat\n"
+ " [6] Sabtu\n\n"
+ "Pasaran Jawa\n"
+ " [0] Legi\n"
+ " [1] Pahing\n"
+ " [2] Pon\n"
+ " [3] Wage\n"
+ " [4] Kliwon\n\n"
+ "Masukkan nomor hari ini : ");
int hari = s.nextInt();
System.out.print("Masukkan pasaran Jawa hari ini : ");
int pasar = s.nextInt();
System.out.print("Masukkan jumlah hari ke depan : ");
int depan = s.nextInt();
int hariDepan = (hari + depan) % 7;
int pasarDepan = (pasar + depan) % 5;
if (hari < 0 || hari > 6 || pasar < 0 || pasar > 4 || depan < 1) {
System.out.println("Kamu salah input. Silahkan cek lagi.");
System.exit(0);
} else {
switch (hari) {
case 0:
System.out.print("Hari ini MINGGU");
break;
case 1:
System.out.print("Hari ini SENIN");
break;
case 2:
System.out.print("Hari ini SELASA");
break;
case 3:
System.out.print("Hari ini RABU");
break;
case 4:
System.out.print("Hari ini KAMIS");
break;
case 5:
System.out.print("Hari ini JUMAT");
break;
case 6:
System.out.print("Hari ini SABTU");
break;
default:
break;
}
switch (pasar) {
case 0:
System.out.print(" LEGI. ");
break;
case 1:
System.out.print(" PAHING. ");
break;
case 2:
System.out.print(" PON. ");
break;
case 3:
System.out.print(" WAGE. ");
break;
case 4:
System.out.print(" KLIWON. ");
break;
default:
break;
}
System.out.print(depan + " hari lagi ");
switch (hariDepan) {
case 0:
System.out.print("MINGGU");
break;
case 1:
System.out.print("SENIN");
break;
case 2:
System.out.print("SELASA");
break;
case 3:
System.out.print("RABU");
break;
case 4:
System.out.print("KAMIS");
break;
case 5:
System.out.print("JUMAT");
break;
case 6:
System.out.print("SABTU");
break;
default:
break;
}
switch (pasarDepan) {
case 0:
System.out.print(" LEGI.");
break;
case 1:
System.out.print(" PAHING.");
break;
case 2:
System.out.print(" PON.");
break;
case 3:
System.out.print(" WAGE.");
break;
case 4:
System.out.print(" KLIWON.");
break;
default:
break;
}
}
}
}
Download here
0 Response to "menentukan hari dan pasaran jawa"
Post a Comment