Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Ue3;
- import java.util.Scanner;
- public class Jahreszeit {
- public static String jahreszeitBestimmung (){
- int tag = 0;
- int monat = 0;
- String jahreszeit="test";
- boolean kombi=true;
- do{
- while(tag==0){
- Scanner z = new Scanner(System.in);
- System.out.print("Tag eingeben (1-31): ");
- if(z.hasNextInt()){
- tag=z.nextInt();
- }
- else {
- System.out.println("Keine ganze Zahl. Bitte Nochmal");
- }
- if(tag<1||tag>31){
- System.out.println("Bitte im Bereich [1-31]! Nochmal.");
- tag=0;
- }
- }
- while(monat==0){
- Scanner y = new Scanner(System.in);
- System.out.print("Monat eingeben (1-12): ");
- if(y.hasNextInt()){
- monat=y.nextInt();
- }
- else {
- System.out.println("Keine ganze Zahl. Bitte Nochmal");
- }
- if(monat<1||monat>12){
- System.out.println("Bitte im Bereich [1-12]! Nochmal.");
- monat=0;
- }
- }
- if(monat==1&&tag>31||monat==2&&tag>29||monat==3&&tag>31||monat==4&&tag>30||monat==5&&tag>31||monat==6&&tag>30||monat==7&&tag>31||monat==8&&tag>31||monat==9&&tag>30||monat==10&&tag>31||monat==11&&tag>30||monat==12&&tag>31){
- System.out.println("Ungültiges Datum. Nochmal.");
- kombi=false;
- }
- }while(kombi==false);
- if(monat==12&&tag==21||monat==1&&tag<=31||monat==2&&tag<=29||monat==3&&tag<20){
- jahreszeit="Winter";
- }
- if(monat==3&&tag>=20||monat==4&&tag<=30||monat==5&&tag<=31||monat==6&&tag<20){
- jahreszeit="Frühling";
- }
- if(monat==6&&tag>=21||monat==7&&tag<=31||monat==8&&tag<=31||monat==9&&tag<21){
- jahreszeit="Sommer";
- }
- if(monat==9&&tag>=21||monat==10&&tag<=31||monat==11&&tag<=30||monat==12&&tag<20){
- jahreszeit="Herbst";
- }
- return jahreszeit;
- }
- public static void main(String[] args) {
- //while(true){
- System.out.println(jahreszeitBestimmung());//}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement