码迷,mamicode.com
首页 > 其他好文 > 详细

HW6.25

时间:2016-08-28 16:31:57      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8         System.out.print("Enter a, b, c: ");
 9         double[] equtation = new double[3];
10         double[] roots = new double[2];
11         for(int i = 0; i < 3; i++)
12             equtation[i] = input.nextDouble();
13 
14         input.close();
15 
16         if(solveQuadratic(equtation, roots) > 0)
17             System.out.println(roots[0] + " " + roots[1]);
18     }
19 
20     public static int solveQuadratic(double[] equ, double[] roots)
21     {
22         double delta = equ[1] * equ[1] - 4 * equ[0] * equ[2];
23         if(delta > 0)
24         {
25             roots[0] = (-equ[1] + Math.sqrt(delta)) / (2 * equ[0]);
26             roots[1] = (-equ[1] - Math.sqrt(delta)) / (2 * equ[0]);
27             return 2;
28         }
29         else if(delta == 0)
30         {
31             roots[0] = -equ[1] / (2 * equ[0]);
32             roots[1] = -equ[1] / (2 * equ[0]);
33             return 1;
34         }
35         else
36             return 0;
37     }
38 }

 

HW6.25

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5815183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!