Kali ini saya akan membagikan cara menentukan waktu yang akan datang, . . biar tidak pada bngung langsung saja di coba ya, . .
import java.util.Scanner;
public class FutureDate {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Enter today's date (0 - 6): ");
int today = s.nextInt();
System.out.print("Enter the number of days elapsed since today: ");
int futureDay = s.nextInt();
if (today < 0 || today > 6 || futureDay < 1) {
System.out.println("Your input is invalid. Please check again!");
System.exit(0);
}
else if (today == 0) {
System.out.print("Today is Sunday");
}
else if (today == 1) {
System.out.print("Today is Monday");
}
else if (today == 2) {
System.out.print("Today is Tuesday");
}
else if (today == 30) {
System.out.print("Today is Wednesday");
}
else if (today == 4) {
System.out.print("Today is Thursday");
}
else if (today == 5) {
System.out.print("Today is Friday");
} else {
System.out.print("Today is Saturday");
}
int day = (today + futureDay) % 7;
if (day == 1) {
switch (day) {
case 0:
System.out.println(" and the next " + futureDay + " day is Sunday");
break;
case 1:
System.out.println(" and the next " + futureDay + " day is Monday");
break;
case 2:
System.out.println(" and the next " + futureDay + " day is Tuesday");
break;
case 3:
System.out.println(" and the next " + futureDay + " day is Wednesdat");
break;
case 4:
System.out.println(" and the next " + futureDay + " day is Thursday");
break;
case 5:
System.out.println(" and the next " + futureDay + " day is Friday");
break;
case 6:
System.out.println(" and the next " + futureDay + " day is Saturday");
break;
default:
System.out.print("Wrong input!");
break;
}
} else {
switch (day) {
case 0:
System.out.println(" and the next " + futureDay + " days is Sunday");
break;
case 1:
System.out.println(" and the next " + futureDay + " days is Monday");
break;
case 2:
System.out.println(" and the next " + futureDay + " days is Tuesday");
break;
case 3:
System.out.println(" and the next " + futureDay + " days is Wednesdat");
break;
case 4:
System.out.println(" and the next " + futureDay + " days is Thursday");
break;
case 5:
System.out.println(" and the next " + futureDay + " days is Friday");
break;
case 6:
System.out.println(" and the next " + futureDay + " days is Saturday");
break;
default:
System.out.print("Wrong input!");
break;
}
}
}
}
Thanks for visiting, . . Semoga bermanfaat, ..
0 Response to "Menentukan Tanggal Yang Akan Datang"
Post a Comment