Ini share tentang tugas java untuk menampilkan waktu.
Langsung aja -->
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
public class Siang_Malam {
public static void main(String[] args){
Calendar calendar = new GregorianCalendar();
String am_pm, good = null, nama;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
if(calendar.get(Calendar.AM_PM) == 0)
am_pm = "AM";
else
am_pm = "PM";
if(calendar.get(Calendar.AM_PM) == 0){
am_pm ="AM";
if (hour <=10){
good = "Pagi";
}
else if (hour >10){
good = "Siang";
}
}
else{
am_pm ="PM";
if(hour <=3){
good ="Siang";
}
else if(hour<=6){
good="Sore";
}
else{
good="Malam";
}
}
nama = JOptionPane.showInputDialog("Input Nama");
JOptionPane.showMessageDialog(null,"Selamat "+ good + " " + nama);
}
}
Semoga Bermanfaat ^^
Tidak ada komentar:
Posting Komentar