㈠ 用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;
}