解一元二次方程的根+求解2*2线性方程



import java.util.Scanner;
public class Switch {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        System.out.println("enter a b and c");

        double a = input.nextDouble();

        double b = input.nextDouble();
        double c = input.nextDouble();

        double r = Math.pow(b, 2) - 4 * a * c;

        double r1 = (-b + Math.pow(Math.pow(b, 2) - 4 * a * c, 0.5) )/ 2 * a;

        double r2 =( -b - Math.pow(Math.pow(b, 2) - 4 * a * c, 0.5) )/ 2 * a;
        if (r > 0)

            System.out.println("HAS two roots" + r1 +"and"+ r2);


        else if (r == 0)


            System.out.println("HAS one root" +r2);

        else if (r<0)

             System.out.println("HAS NO root");
    }
}


import java.util.Scanner;
    public class Switch {
    public static void main(String[] args) {

      Scanner input =new Scanner (System.in);
      System.out.println("enter a b c d e f ");

      double a=input.nextDouble();
      double b=input.nextDouble();
      double c=input.nextDouble();
      double d=input.nextDouble();
      double e=input.nextDouble();
      double f=input.nextDouble();
      double p=a*d-b*c;
      double x=(e*d-b*f)/(a*d-b*c);
      double y=(a*f-e*c)/(a*d-b*c);

      if (p!=0)
          System.out.println("x is "+x+"and y is"+y);
      else if(p==0)
    System.out.println("NO solution");
    }


}

你可能感兴趣的:(解一元二次方程的根+求解2*2线性方程)