當前位置:編程學習大全網 - 編程語言 - 編寫求解幾何圖形(如三角形,矩型,圓,多邊型)的周長、面積的應用程序

編寫求解幾何圖形(如三角形,矩型,圓,多邊型)的周長、面積的應用程序

package a;

import java.util.Scanner;

public class Triangle {

double a;

double b;

double c;

public void input()

{Scanner t=new Scanner(System.in);

int a=t.nextInt();

int b=t.nextInt();

int c=t.nextInt();

}

public double perimeter() {

return a + b + c;

}

public double area() {

return ((0.25) * Math.sqrt((a + b + c) * (a + b - c) * (a + c - b) * (b + c - a)));

}

}

package b;

import java.util.Scanner;

public class Circle {

double r;

public void input()

{Scanner t=new Scanner(System.in);

int r=t.nextInt();

}

public double perimeter() {

return 2 * 3.14 * r;

}

public double area() {

return 3.14 * r * r;

}

}

package c;

import java.util.Scanner;

public class Rectangle {

double a;

double b;

public void input()

{Scanner t=new Scanner(System.in);

int a=t.nextInt();

int b=t.nextInt();

}

public double perimeter() {

return 2 * (a + b);

}

public double area() {

return a * b;

}

}

import a.Triangle;

import b.Circle;

import c.Rectangle;

public class Result2{

public static void main(String[] args) {

Triangle s1= new Triangle();

System.out.println("請輸入三角形的三條邊:");

s1.input();

System.out.println("三角形周長:" + s1.perimeter());

System.out.println("三角形面積:" + s1.area());

Circle s2= new Circle();

System.out.println("請輸入圓的半徑:");

s2.input();

System.out.println("圓周長:" + s2.perimeter());

System.out.println("圓面積:" + s2.area());

Rectangle s3= new Rectangle();

System.out.println("請輸入矩形的長和寬:");

s3.input();

System.out.println("矩形周長:" + s3.perimeter());

System.out.println("矩形面積:"+ s3.area());

}

}

  • 上一篇:用Java邏輯思維,前十章做壹個小遊戲。可以在MyEclipse8.5運行的。帶註釋。謝謝。
  • 下一篇:計算機2級VFP教程
  • copyright 2024編程學習大全網