0/5 (2 avis)
Snippet vu 10 718 fois - Téléchargée 29 fois
import java.io.*; import java.lang.*; import java.lang.Math.*; import java.awt.*; import javax.swing.JOptionPane; class Complexes extends Frame { public int x,y,z; Complexes() { String a1,b1,c1; a1 = JOptionPane.showInputDialog(null,"Veuillez entrer la valeur de a : ", "Input",JOptionPane.INFORMATION_MESSAGE); if (a1 == null) System.exit(0); b1 = JOptionPane.showInputDialog(null,"Veuillez entrer la valeur de b : ", "Input",JOptionPane.INFORMATION_MESSAGE); if (b1 == null) System.exit(0); c1 = JOptionPane.showInputDialog(null,"Veuillez entrer la valeur de c : ", "Input",JOptionPane.INFORMATION_MESSAGE); if (c1 == null) System.exit(0); x=Integer.parseInt(a1); y=Integer.parseInt(b1); z=Integer.parseInt(c1); } double Delta() { double d; d = y*y-4*x*z; return d; } double x1(double de) { return (-y-java.lang.Math.sqrt(de))/(2*x); } double x2(double de) { return (-y+java.lang.Math.sqrt(de))/(2*x); } double x3() { return (-y/(2*x)); } double xc(double de) { return (java.lang.Math.sqrt(-de)/(2*x)); } } class Prog { public static void main(String arg[]) { int retour=JOptionPane.NO_OPTION; double s; double x1,x2; Frame f; Panel p1; while (retour!=JOptionPane.YES_OPTION) { f = new Frame("Résolution d'une equation du type ax²+bx+c=0"); p1 = new Panel(); p1.setLayout(new BorderLayout(10,10)); f.add("North",new Label("Résolution d'une equation du type ax²+bx+c=0")); Complexes pol; pol = new Complexes(); s = pol.Delta(); f.add("West",new Label("Delta = "+ s)); if (s>0) { x1= pol.x1(s); x2= pol.x2(s); f.add("South",new Label("Deux solutions : x1 = "+ x1+" x2 = "+ x2)); } if (s==0) { x1=pol.x3(); f.add("South",new Label("La solution est : x = " + x1)); } if (s<0) { x1=pol.x3(); x2=pol.xc(s); f.add("South",new Label("Deux solutions : x1 = "+ x1+" + i "+ x2+" x2 = "+ x1+" - i "+x2)); } f.pack(); f.show(); retour=JOptionPane.showConfirmDialog(null,"Voulez-vous quitter ?", "Hey!",JOptionPane.YES_NO_OPTION); f.dispose(); } System.exit(0); } }
16 juin 2003 à 23:30
16 juin 2003 à 23:21
;-)
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.