现在的位置: 首页 > 综合 > 正文

java小程序

2011年07月06日 ⁄ 综合 ⁄ 共 818字 ⁄ 字号 评论关闭

 

 1 import java.util.*;
2 public class TriangleArea {
3 double triWide; //长方形的宽
4 double triLength; //长方形的长
5 double cirRadius; //圆的半径
6
7 /* 求圆面积方法方法如下 */
8 public double getCircleArea(double radius) {
9 return 3.14*radius*radius;
10 }
11
12 /* 求长方形面积方法如下 */
13 public double getTriangleArea(double length, double wide) {
14 return length*wide;
15 }
16 public static void main(String[] args) {
17 // TODO Auto-generated method stub
18 TriangleArea tricir = new TriangleArea();
19 Scanner reader = new Scanner(System.in);
20 System.out.println("输入长方形的长");
21 tricir.triLength = reader.nextDouble();
22 System.out.println("输入长方形的宽");
23 tricir.triWide = reader.nextDouble();
24 System.out.println("长方形面积为:"+tricir.getTriangleArea(tricir.triLength, tricir.triWide));
25 System.out.println("输入圆的半径");
26 tricir.cirRadius = reader.nextDouble();
27 System.out.println("这个圆的面积为:"+tricir.getCircleArea(tricir.cirRadius));
28 }
29 }

抱歉!评论已关闭.