Last active
June 11, 2016 21:36
-
-
Save josinSbazin/972f5a9e6d3e906ccad5c47706115fdb to your computer and use it in GitHub Desktop.
level08.lesson11.bonus01 - через Date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level08.lesson11.bonus01; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.*; | |
/* Номер месяца | |
Программа вводит с клавиатуры имя месяца и выводит его номер на экран в виде: «May is 5 month». | |
Используйте коллекции. | |
*/ | |
public class Solution { | |
public static void main(String[] args) throws IOException { | |
one: | |
while(true) { | |
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); | |
String month = reader.readLine(); | |
month=month.substring(0,1).toUpperCase() + month.substring(1).toLowerCase(); | |
try { | |
Date m = new Date(month + " 2 1999"); | |
System.out.println(month + " is " + (int) (m.getMonth() + 1) + " month"); | |
} | |
catch (IllegalArgumentException e) { | |
System.out.println("Невозможно определить месяц. Попробуйте еще раз: "); | |
continue one; | |
} | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment