Skip to content

Instantly share code, notes, and snippets.

@sangpt
Last active November 10, 2016 07:28
Show Gist options
  • Save sangpt/b5299a2d3fb68bda3ebe17b298c1765b to your computer and use it in GitHub Desktop.
Save sangpt/b5299a2d3fb68bda3ebe17b298c1765b to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package btvn3;
import javax.swing.JOptionPane;
/**
*
* @author Kawaii
*/
public class ThangNam {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Pham Tuan Sang - 20146596");
String strThang, strNam;
int thang, nam;
int thang2;
do {
strThang = JOptionPane.showInputDialog(null, "Nhap thang: ");
thang = Integer.parseInt(strThang);
} while (thang < 1 || thang > 12);
do {
strNam = JOptionPane.showInputDialog(null, "Nhap nam: ");
nam = Integer.parseInt(strNam);
} while (nam < 0);
if (nam % 4 == 0) {
if (nam % 100 == 0 && nam % 400 != 0) {
thang2 = 28;
} else {
thang2 = 29;
}
} else {
thang2 = 28;
}
switch (thang) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
JOptionPane.showMessageDialog(null, "Thang nay co 31 ngay");
break;
case 4:
case 6:
case 9:
case 11:
JOptionPane.showMessageDialog(null, "Thang nay co 30 ngay");
break;
case 2:
JOptionPane.showMessageDialog(null, "Thang nay co " + thang2 + " ngay");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment