统计信息

  • 访问数:14554
  • 博客数:143
  • 建立时间:2008-01-05
  • 更新时间:2008-10-15
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

P2Q9

2008-01-25 23:07:41

天气: 晴朗 心情: 高兴

/*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);
  }
 

  }
}


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd