Skip to content

Instantly share code, notes, and snippets.

@guidanoli
Created October 10, 2014 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guidanoli/d1647c28f7afffc99e51 to your computer and use it in GitHub Desktop.
Save guidanoli/d1647c28f7afffc99e51 to your computer and use it in GitHub Desktop.
Equação do 2º grau
import javax.swing.*;
import java.math.*;
public class HelloWorld{
public static void main(String args[]){
double delta,a,b,c,x1,x2;
String vat; //vat=Valor ATual
JOptionPane.showMessageDialog(null,"Bem-vindo ao calculador de equação do 2º grau!");
vat = JOptionPane.showInputDialog("Insira o coeficiente a");
a = Float.parseFloat(vat.trim());
vat = JOptionPane.showInputDialog("Insira o coeficiente b");
b = Float.parseFloat(vat.trim());
vat = JOptionPane.showInputDialog("Insira o coeficiente c");
c = Float.parseFloat(vat.trim());
//valores armazenados em a, b e c
delta = Math.pow(b, 2)-(4*a*c); //delta calculado
x1 = (-b+delta)/(2*a);
x2 = (-b-delta)/(2*a);
JOptionPane.showMessageDialog(null, "Os resultados são "+x1+" e "+x2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment