/* NaesteDato.java * Author: Kris og Anne * * Opgave 11 til 4. semester-uge: * Beregner naeste dags dato */ import cs1.Keyboard; public class NaesteDato { public static void main(String[] args) { int daysinmonth=0,day=0,month=0,year=0; // indlaes aar do { System.out.print("Indtast år (mellem 2000 og 2999): "); year = Keyboard.readInt(); } while (year<2000 || year>2999); // indlaes maaned do { System.out.print("Indtast måned: "); month = Keyboard.readInt(); } while (month<1 || month>12); //beregn antal dage i maaneden switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: daysinmonth=31; break; case 2: { if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )//Skudaar! daysinmonth=29; else daysinmonth=28; } break; default: daysinmonth=30; } //indlaes dag do { System.out.print("Indtast dag: "); day = Keyboard.readInt(); } while (day<1 || day>daysinmonth); System.out.print("Dagen efter " + day + "/" + month + " " + year + " er "); //beregn naeste dags dato og udskriv resultatet if (day==daysinmonth) { day=1; if (month!=12)//Ikke december month++; else { month=1; year++; } } else day++; System.out.println(day + "/" + month + " " + year); } }