Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class kap4_opg3{
- public static void main(String[] args){
- Scanner console = new Scanner(System.in);
- System.out.print("Write a date like this \"27/7\" for 27th of July: ");
- String date = console.next();
- System.out.println("You wrote: "+date);
- System.out.println("Which is "+season(date));
- }
- public static String season(String dateAndMonth){
- String[] dates = dateAndMonth.split("/");
- int date = Integer.parseInt(dates[0]); // converts the date into an integer
- int month = Integer.parseInt(dates[1]); // converts the month into an integer
- int day = 0;
- switch(month){
- case 1:
- day = date;
- break;
- case 2:
- day = 31+date; // there are 31 days in January.
- break;
- case 3:
- day = 59+date; // there are 28 days in February.
- break;
- case 4:
- day = 90+date; // there are 31 days in March.
- break;
- case 5:
- day = 120+date; // there are 30 days in April.
- break;
- case 6:
- day = 151+date; // there are 31 days in May
- break;
- case 7:
- day = 181+date; // there are 30 days in June
- break;
- case 8:
- day = 212+date; // 31 in July
- break;
- case 9:
- day = 243+date; // 31 in August
- break;
- case 10:
- day = 273+date; // 30 in September
- break;
- case 11:
- day = 304+date; //31 in October
- break;
- case 12:
- day = 334+date; // 30 in November
- break;
- }
- String season = "";
- if(day<=74||day>=350){ // 74 = 15/3 and 350 = 16/12
- season = "Winter";
- }else if(day>=75&&day<=166){ // 75 = 16/3 and 166 = 15/5
- season = "Spring";
- }else if(day>=167&&day<=258){ // 167 = 16/5 and 258 = 15/9
- season = "Summer";
- }else if(day>=259&&day<=349){ // 259 = 16/9 and 349 = 15/12
- season = "Fall";
- }
- return season;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement