Fare丶梦


私信TA

用户名:126913199

访问量:41040

签 名:

等  级
排  名 237
经  验 6107
参赛次数 0
文章发表 50
年  龄 22
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

import java.util.Scanner;

import java.text.DecimalFormat;


public class Main {

        static DecimalFormat df = new DecimalFormat("0.000");

        public static void panduan(float a,float b,float c){

                if(b*b-4*a*c<0)

                        xu(a,b,c);

                else if(b*b-4*a*c==0)

                        weiyi(a,b,c);

                else

                        shi(a,b,c);

                }

        public static void xu(float a,float b,float c){

                float x = -b/(2*a);

                float x1 = (float) (Math.sqrt(-b*b+4*a*c))/(2*a);

                float x2 = (float) (Math.sqrt(-b*b+4*a*c))/(2*a);

                System.out.print("x1="+df.format(x)+"+"+df.format(x1) +"i"+" "+"x2="+df.format(x)+"-"+df.format(x2)+"i");

        }

        public static void weiyi(float a,float b,float c){

                float x = -b/(2*a);

                System.out.print("x="+df.format(x));

        }

        public static void shi(float a,float b,float c){

                float x1 = (float) ((-b+Math.sqrt(b*b-4*a*c))/(2*a));

                float x2 = (float) ((-b-Math.sqrt(b*b-4*a*c))/(2*a));

                System.out.print("x1="+df.format(x1)+" x2="+df.format(x2));

        }

        public static void main(String[] arg){

                float a,b,c;

                Scanner sc = new Scanner(System.in);

                a = sc.nextInt();

                b = sc.nextInt();

                c = sc.nextInt();

                panduan(a, b, c);

        }

}


 

0.0分

2 人评分

  评论区

  • «
  • »