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

Langage Java Discussion :

maths puissance en java.


Sujet :

Langage Java

  1. #1
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut maths puissance en java.
    Bonjour tout le monde

    Je veux faire le calul un plynome.

    Je n'obtiens aucun résultat.

    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
    24
     
    class Fonction {
     
     
     
    public double calculpolynome(float ax, float ay, float az, float expo){
     
    float resu = 0;
     
    float tp;
     
    int i;
     
     
     resu = Math.pow(ax, expo) + 2 * Math.pow(ay, expo-1) + 3 * az;
     
     
     
    return resu;
    }
     
     
     
    }
    Faut il faire un import.

    Dois modifier le code?

    A +

  2. #2
    Membre expérimenté Avatar de willoi
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    1 355
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 355
    Points : 1 639
    Points
    1 639
    Par défaut
    A priori non tu n'as pas besoin d'import speciaux.
    Si c'etait le cas tu aurais une erreur de compilation.

    Quand tu dis que tu n'obtiens aucun resultat ca signifie quoi exactement ?

  3. #3
    Membre chevronné
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Points : 1 787
    Points
    1 787
    Par défaut
    Normalement oui cette fonction a l'air correcte (sauf conventions de nommage )

  4. #4
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut
    Bonjour tout le monde

    Je crois que le probleme vient de la conversion de chaine en doube, je vous ais mis l'erreur d'execution.

    J'ignore la commande pour la conversion de string en double.

    Voici la conversion string en double.

    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
     
    float a = Float.valueOf(x1.getText());
     
     
    float b = Float.valueOf(x2.getText());
     
     
    double e = Float.valueOf(exp.getText());
     
    double ab = Float.valueOf(ax.getText());
     
     
    double ac = Float.valueOf(ax2.getText());
     
    double ad = Float.valueOf(ax3.getText());
     
    total.setText(Double.toString(intergal.calculpolynome(ab,ac,ad,e)));
    Voici le calcul
    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
    24
    25
    26
     
     
     
    class Fonction {
     
     
     
    public double calculpolynome(double ax, double ay, double az, double expo){
     
    double resu = 0;
     
    float tp;
     
    int i;
     
     
     resu = Math.pow(ax, expo) + 2 * Math.pow(ay, expo-1) + 3 * az;
     
     
     
    return resu;
    }
     
     
     
    }

    Voici l'erreur d'execution

    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty St
    ring
    at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    at java.lang.Float.valueOf(Unknown Source)
    at CompoFonction.actionPerformed(CompoFonction.java:569)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
    ce)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty St
    ring
    at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
    at java.lang.Float.valueOf(Unknown Source)
    at CompoFonction.actionPerformed(CompoFonction.java:569)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
    ce)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    A +

  5. #5
    Membre expérimenté Avatar de willoi
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    1 355
    Détails du profil
    Informations personnelles :
    Âge : 51
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Décembre 2006
    Messages : 1 355
    Points : 1 639
    Points
    1 639
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    float a = Float.valueOf(x1.getText());
     
     
    float b = Float.valueOf(x2.getText());
     
     
    double e = Float.valueOf(exp.getText());
     
    double ab = Float.valueOf(ax.getText());
     
     
    double ac = Float.valueOf(ax2.getText());
     
    double ad = Float.valueOf(ax3.getText());
    Une de ces chaines de caracteres est vide, apparement c'est ce qui pose probleme.

  6. #6
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut
    Re bonjour

    J'ai réglé mon problème

    Voici le code

    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
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
     
    if(source==calculer)
    {
     
    float a;
     
     
    float b;
     
     
    double ex;
    double ab;
     
     
    double ac;
     
    double ad;
     
     
     
    try {
     
    a = Float.valueOf(x1.getText());
     
     
    b = Float.valueOf(x2.getText());
     
     
    ex = Float.valueOf(exp.getText());
     
    ab = Float.valueOf(ax.getText());
     
     
    ac = Float.valueOf(ax2.getText());
     
    ad = Float.valueOf(ax3.getText());
     
     
    total.setText(Double.toString(intergal.calculpolynome(ab,ac,ad,ex)));
     
    }
    catch(NumberFormatException e)
    {
     
    Toolkit.getDefaultToolkit().beep();
    JOptionPane.showMessageDialog(null,"Format entré incorrect.","Erreur de saisie",JOptionPane.ERROR_MESSAGE);
     
     
    }
     
     
     
     
     
    }
    A+

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

Discussions similaires

  1. Coupler la puissance de Java EE et PHP grâce à GlassFish
    Par Ricky81 dans le forum Glassfish et Payara
    Réponses: 14
    Dernier message: 07/02/2014, 14h06
  2. calcul de puissance en java
    Par oumay dans le forum Débuter avec Java
    Réponses: 2
    Dernier message: 22/02/2010, 22h43
  3. calcul de la puissance en java
    Par osman.amine dans le forum Général Java
    Réponses: 5
    Dernier message: 02/08/2007, 10h37
  4. [Math]Valider une formule mathematique en java
    Par RolandB dans le forum API standards et tierces
    Réponses: 7
    Dernier message: 22/04/2005, 09h09

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