public class Quad1
public static void main(String[] args)
{
int a = 2;
int b = 6;
int c = 4;
//Finding out the roots
double temp1 = Math.sqrt(b * b - 4 * a * c);
double root1 = (-b + temp1) / (2*a) ;
double root2 = (-b - temp1) / (2*a) ;
System.out.println("The roots of the Quadratic Equation \"2x2 + 6x + 4 = 0\" are "+root1+" and "+root2);
}
}
-------------------------------------------------------------------------
import java.util.Scanner;
public class Calc{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the values of a, b and c");
double a = scanner.nextDouble();
double b = scanner.nextDouble();
double c = scanner.nextDouble();
double r1 = 0;
double r2 = 0;
double discriminant = b * b - 4 * a * c;
if (discriminant > 0){
// r = -b / 2 * a;
r1 = (-b + Math.sqrt(discriminant)) / (2 * a);
r2 = (-b - Math.sqrt(discriminant)) / (2 * a);
System.out.println("The equation has two real roots " + r1 + " and " + r2);
}
if (discriminant == 0){
System.out.println("The equation has one root " +r1);
r1 = -b / (2 * a);
r2 = -b / (2 * a);
}
if (discriminant < 0){
System.out.println("The equation has no real root");
}
}
}
--------------------------------------------------------------------------------------
import java.io.*;
class Qua
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader (System.in);
BufferedReader in=new BufferedReader (read);
System.out.println("a=");
int a=Integer.parseInt(in.readLine());
System.out.println("b=");
int b=Integer.parseInt(in.readLine());
System.out.println("c=");
int c=Integer.parseInt(in.readLine());
double dis = Math.sqrt(b*b-4*a*c);
double c1=(-b+dis)/(2*a);
double c2=(+b+dis)/(2*a);
System.out.println("Either "+c1+"or"+c2);
}
}
---------------------------------------------------------------------------
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();
}
}
public static void main(String[] args)
{
int a = 2;
int b = 6;
int c = 4;
//Finding out the roots
double temp1 = Math.sqrt(b * b - 4 * a * c);
double root1 = (-b + temp1) / (2*a) ;
double root2 = (-b - temp1) / (2*a) ;
System.out.println("The roots of the Quadratic Equation \"2x2 + 6x + 4 = 0\" are "+root1+" and "+root2);
}
}
-------------------------------------------------------------------------
import java.util.Scanner;
public class Calc{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the values of a, b and c");
double a = scanner.nextDouble();
double b = scanner.nextDouble();
double c = scanner.nextDouble();
double r1 = 0;
double r2 = 0;
double discriminant = b * b - 4 * a * c;
if (discriminant > 0){
// r = -b / 2 * a;
r1 = (-b + Math.sqrt(discriminant)) / (2 * a);
r2 = (-b - Math.sqrt(discriminant)) / (2 * a);
System.out.println("The equation has two real roots " + r1 + " and " + r2);
}
if (discriminant == 0){
System.out.println("The equation has one root " +r1);
r1 = -b / (2 * a);
r2 = -b / (2 * a);
}
if (discriminant < 0){
System.out.println("The equation has no real root");
}
}
}
--------------------------------------------------------------------------------------
import java.io.*;
class Qua
{
public static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader (System.in);
BufferedReader in=new BufferedReader (read);
System.out.println("a=");
int a=Integer.parseInt(in.readLine());
System.out.println("b=");
int b=Integer.parseInt(in.readLine());
System.out.println("c=");
int c=Integer.parseInt(in.readLine());
double dis = Math.sqrt(b*b-4*a*c);
double c1=(-b+dis)/(2*a);
double c2=(+b+dis)/(2*a);
System.out.println("Either "+c1+"or"+c2);
}
}
---------------------------------------------------------------------------
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