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

HW3.1

时间:2016-08-09 13:41:31      阅读:185      评论: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 
 9         System.out.print("Enter a, b, c: ");
10         double a = input.nextDouble();
11         double b = input.nextDouble();
12         double c = input.nextDouble();
13 
14         input.close();
15 
16         double delta = b * b - 4 * a * c;
17 
18         if(delta > 0)
19         {
20             double root1 = (-b + Math.pow(delta, 0.5)) / (2 * a);
21             double root2 = (-b - Math.pow(delta, 0.5)) / (2 * a);
22             System.out.println("The roots are " + root1 + " and " + root2);
23         }
24         else if(delta == 0)
25         {
26             double root = -b / (2 * a);
27             System.out.println("The root is " + root);
28         }
29         else
30             System.out.println("The equation has no real roots.");
31     }
32 }

 

HW3.1

标签:

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

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