IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Collection et Stream Java Discussion :

Date en jours - mois - ans


Sujet :

Collection et Stream Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2009
    Messages
    469
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2009
    Messages : 469
    Points : 149
    Points
    149
    Par défaut Date en jours - mois - ans
    Bon WE a tous,

    Le code ci dessous m indique une erreur au niveau system.out....

    Quelqu'un pourrait-il m'eclairer


    Habiler

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    import java.time.*;
    /**
     *
     * @author hab
     */
    public class NewClass1 {
    LocalDate endofCentury = LocalDate.of(2014, 01, 01);
    LocalDate now = LocalDate.now();
     
    Period diff = Period.between(endofCentury, now);
     
    System.out.println("Difference is %d years, %d months and %d days old", 
                        diff.getYears(), diff.getMonths(), diff.getDays());

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
     
    Compiling 5 source files to C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\build\classes
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\src\NewClass1.java:13: error: <identifier> expected
    System.out.println("Difference is %d years, %d months and %d days old", 
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\src\NewClass1.java:13: error: illegal start of type
    System.out.println("Difference is %d years, %d months and %d days old", 
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\src\NewClass1.java:14: error: <identifier> expected
                        diff.getYears(), diff.getMonths(), diff.getDays());
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\src\NewClass1.java:14: error: ';' expected
                        diff.getYears(), diff.getMonths(), diff.getDays());
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\src\NewClass1.java:14: error: illegal start of type
                        diff.getYears(), diff.getMonths(), diff.getDays());
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\src\NewClass1.java:14: error: ';' expected
                        diff.getYears(), diff.getMonths(), diff.getDays());
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\src\NewClass1.java:14: error: invalid method declaration; return type required
                        diff.getYears(), diff.getMonths(), diff.getDays());
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\src\NewClass1.java:14: error: ';' expected
                        diff.getYears(), diff.getMonths(), diff.getDays());
    8 errors
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\nbproject\build-impl.xml:954: The following error occurred while executing this line:
    C:\Users\hab\Documents\NetBeansProjects\GUIFormExamples\JavaApplication29\nbproject\build-impl.xml:294: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Ton code doit se trouver dans une méthode. Tu ne peux pas mettre du code comme ça juste dans la classe. Une classe est constituée uniquement de champs et de méthode (y compris constructeurs), pas de code. Le code va dans les méthodes.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] Comment récupérer des données de la date actuelle(jour/mois)
    Par Aiglichon dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 26/12/2012, 19h39
  2. [XL-2003] Recherche d'un format DATE (Journée, jour, mois, année)
    Par Myaka dans le forum Excel
    Réponses: 2
    Dernier message: 27/10/2011, 19h44
  3. Regrouper des dates sur jour moi annee
    Par madmaxou dans le forum SQL
    Réponses: 5
    Dernier message: 02/05/2011, 10h19
  4. Table Date(Année jour mois )
    Par Kalas22 dans le forum Requêtes
    Réponses: 1
    Dernier message: 20/04/2011, 18h46
  5. Réponses: 1
    Dernier message: 09/12/2010, 09h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo