Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ewiger Kalender

Empfohlene Antworten

Hallo,

hab ein problem, ich soll für meinen Lehrer einen Ewigen Kalender schreiben bis jetzt hat das auch super funktioniert.


import java.util.*;

import java.text.*;

import java.io.*;


public static void main(String args[]){

        String format = "TT.MM.JJJJ";

        System.out.println("Datum eingeben ("+format+"): ");

        String eingabe="";

        String[] gespalten={};

        String[] deutsche_tage={

                "Montag",

                "Dienstag",

                "Mittwoch",

                "Donnerstag",

                "Freitag",

                "Samstag",

                "Sonntag"

        };


        try {

                BufferedReader in = new BufferedReader(

                new InputStreamReader( System.in ) );

                eingabe=in.readLine();

        } catch( IOException ex ) {

                System.out.println( ex.getMessage() );

        }

        gespalten = eingabe.split("\\.");


        if(gespalten.length==3) {


                int eingabe_tag=-1;

                int eingabe_monat=-1;

                int eingabe_jahr=-1;



                try {

                eingabe_tag=Integer.parseInt(gespalten[0]);

                eingabe_monat=Integer.parseInt(gespalten[1]);

                eingabe_jahr=Integer.parseInt(gespalten[2]);

                } catch (NumberFormatException n_ex) {

                        System.out.println("Falsches Datumsformat!!!, bitte "+format+" benutzen!");

                }


                if(

                        eingabe_tag!=-1 &&

                        eingabe_monat!=-1 &&

                        eingabe_jahr!=-1

                ) {

                        GregorianCalendar cal = new GregorianCalendar(

                                eingabe_tag,

                                eingabe_monat,

                                eingabe_jahr

                        );

                        int day = cal.get(Calendar.DAY_OF_WEEK);

                        System.out.println("Der "+eingabe+" ist ein "+deutsche_tage[(day+2)%7]+". ");

                }


        } else{


                System.out.println("Falsches Datumsformat!!!, bitte "+format+" benutzen!");


        }




}

}
Da ich noch anfänger bin hat mir jemand dabei geholfen, jetzt hab ich nur ein problem. Ich kann den 32.02.2009 eingben, denn es ja nicht gibt. In der Schule haben wir ein paar methoden benutzt um sowas zu verhindern

    public static boolean istSchaltjahr(int a){

    return (a % 4 == 0 && a % 100!= 0 || a % 400 == 0)?true: false;

  }

   public static boolean eingabe_monat(int m){

    return((m>=1)&&(m<=12))? true:false;

  }


 public static boolean eingabe_jahr(int j){

    return((j>=1586)&&(j<=9999))? true:false;

  }


  public static boolean eingabe_tag(int t, int m, int j){

    boolean istMonat31 = (m==1)||(m==3)||(m==5)||(m==7)||(m==8)||(m==10)||(m==12);

    boolean istMonat30 = (m==4)||(m==6)||(m==9)||(m==11);

    boolean istMonat29 = istSchaltjahr(j);

    boolean istMonat28 = !istSchaltjahr(j);


    boolean istTag31 = istMonat31 &&(t>=1) &&(t<=31);

    boolean istTag30 = istMonat30 &&(t>=1) &&(t<=30);

    boolean istTag29 = istMonat29 &&(t>=1) &&(t<=29);

    boolean istTag28 = istMonat28 &&(t>=1) &&(t<=28);


    return istTag31||istTag30||istTag29||istTag28;

  }


  public static boolean istDatum(int t, int m, int j){

    if(eingabe_monat(m) && eingabe_jahr(j) && eingabe_tag(t,m,j)) return true;

    else return false;

  }

die habe ich dann alle in mein Programm eingebettet

und ich konnte das auch alles Komplimieren, aber irgendwie funktioniert das nicht so wie es funktionieren sollte, kann mir da jemand helfen? Finde den fehler nicht.


GregorianCalendar cal = new GregorianCalendar(

    eingabe_tag,

    eingabe_monat,

    eingabe_jahr

);

[...] irgendwie funktioniert das nicht so wie es funktionieren sollte [...]

Siehe: Gregorian Calendor (Java 6 API Doc)

Gruß

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.