fork download
  1. import java.util.Scanner;
  2.  
  3. class Main{
  4. public static void main(String[] args) {
  5. int[] year = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  6. Scanner scanner = new Scanner(System.in);
  7. System.out.print("月を入力してください > ");
  8. int month = scanner.nextInt();
  9. try {
  10. System.out.println(month + "月の日数は" + year[month - 1] + "日です");
  11. System.out.println("入力エラーです");
  12. }
  13. }
  14. }
  15.  
Success #stdin #stdout 0.18s 45708KB
stdin
6
stdout
月を入力してください > 6月の日数は30日です