我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P2Q9
* Name:Wang Chaoran
* Description:9 (Computing the perimeter of a triangle)
Write a program that reads three edges for a triangle and computes the perimeter if the input is valid.
Otherwise, display that the input is invalid. The input is valid if the sum of any two edges is greater than the third edge.
*/
import java.util.Scanner;
public class P2Q9
{
public static void main(String[] args)
{
//Step One: Create a scanner
Scanner scan = new Scanner(System.in);
//Step Two: Read in the values of the three edges of the triangle
System.out.println("Please input the value of first edge of the triangle");
Double edgeA = scan.nextDouble();
System.out.println("Please input the value of sencond edge of the triangle");
Double edgeB = scan.nextDouble();
System.out.println("Please input hte value of third edge of the triangle");
Double edgeC = scan.nextDouble();
//Step Three:Make a judgement of the input and output the judgement
if ((edgeA + edgeB <=edgeC)||(edgeA + edgeC <=edgeB)||(edgeA + edgeB <=edgeC))
{
System.out.println("Can edges "+edgeA+", "+edgeB+" and "+edgeC+" form a triangle? false");
}
else
{
Double perimeter=edgeA+edgeB+edgeC;
System.out.println("The perimeter of the triangle is "+perimeter);
}
}
}
导入论坛查看(40)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing