import javax.swing.JOptionPane;
import java.io.*;
class Solution
{
private int a,b,c,desc;
private double r1,r2;
public void solve()
{
desc=b*b-4*a*c;
if(desc>0)
{
r1=(-b+Math.sqrt(desc))/(2*a);
r2=(-b-Math.sqrt(desc))/(2*a);
JOptionPane.showMessageDialog(null,"roots are"+r1+" "+r2,"Message",JOptionPane.INFORMATION_MESSAGE);
}
else if(desc==0)
{
r1=r2=(-b+Math.sqrt(desc))/(2*a);
JOptionPane.showMessageDialog(null,"roots are"+r1+" "+r2,"Message",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null,"there are no real solutions","Message",JOptionPane.INFORMATION_MESSAGE);
}
}
public void input()
{
String n1,n2,n3;
n1=JOptionPane.showInputDialog("enter a value");
n2=JOptionPane.showInputDialog("enter b value");
n3=JOptionPane.showInputDialog("enter c value");
a=Integer.parseInt(n1);
b=Integer.parseInt(n2);
c=Integer.parseInt(n3);
}
}
class Quadratic
{
public static void main(String[] args)
{
Solution s=new Solution();
s.input();
s.solve();
}
}
No comments:
Post a Comment