题解 | #计算三角形的周长和面积#

计算三角形的周长和面积

http://www.nowcoder.com/practice/109a44d649a142d483314e8a57e2c710

import java.util.Scanner;
/*
    海伦公式求面积:
    p = (a + b + c)/2
    s = sqrt(p*(p-a)*(p-b)*(p-c))
*/
public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        double cir;
        double area;
        double p;
        cir = (double)(a + b + c);
        p = cir / 2;
        area = Math.sqrt(p*(p-a)*(p-b)*(p-c));
        System.out.println("circumference=" + String.format("%.2f",cir) + " area=" + String.format("%.2f",area));
    }
} 
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务