㈠ 用java求圓的面積與周長
class Circle {
private int r;
public Circle(int r){
this.r=r;
}
public int getr(){
return r;
}
public double getArea(){
return Math.PI*r*r;
}
public double getCircleLength(){
return Math.PI*2*r;
}
}
public class CircleComputer{
public static void main(String []args){
Circle a=new Circle(1);
System.out.println("圓半徑r= "+a.getr());
System.out.println("圓面積為:"+a.getArea());
System.out.println("圓周長為:"+a.getCircleLength());
}
}
㈡ JAVA編程中求圓的面積怎麼寫
import java.util.Scanner;
//java 並不直接支持控制台輸入,但可以使用Scanner類建立它的對象,已讀取來System.in的輸入
public class KongZhi {
public static void main(String[] args) {
Scanner input = new Scanner( System.in);
System.out.println("Enter a number for radius: ");
double radius = input.nextDouble();
double area= radius*radius*3.14;
System.out.println("The area for the circle of radius "+radius+" "+area);
}
}
(2)java計算圓的面積擴展閱讀:
其他方法求圓的面積:
#include<stdio.h>
#include<math.h>
#define M=3.14
int main()
{
int r;
double s;
scanf("%d",&r);
s=M*pow(r,2);
printf("%0.7lf",s);
return 0;
}