java圆排列代码 java编写一个圆类circle

用java创建10个由圆

class Circle {

创新互联是一家专注于成都网站设计、网站建设与策划设计,西藏网站建设哪家好?创新互联做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:西藏等地区。西藏做网站价格咨询:13518219792

public static final double PI = 3.14159; //圆周率

private double radius; //半径

//构造方法,将半径置为0

public Circle() {

radius = 0.0;

}

//构造方法,创建Circle对象时将半径初始化为r

public Circle(double r) {

this.radius = r;

}

//获得圆的半径值

public double getRadius(){

return this.radius;

}

//获得圆的周长

public double getArea() {

return PI * radius * radius;

}

//获得圆的面积

public double getPerimeter() {

return 2 * PI * radius;

}

// 将圆的半径、周长、面积输出到屏幕

public void disp() {

System.out.println("圆的半径为:"+getRadius()+" 圆的周长为:"+getPerimeter()+" 圆的面积为:"+getArea());

}

}

//测试类

class testCircle {

public static void main(String args[]) {

Circle[] circleArray = new Circle[10];

for (int i = 0; i circleArray.length; i++) {

circleArray[i] = new Circle(Math.random()*100);

}

for (Circle circle : circleArray) {

circle.disp();

}

}

}

急求Java代码,定义一个Circle(圆类型)

public class Exam

{

public static void main(String[] args)

{

Circle c=new Circle(3,4,5);

System.out.printf("圆心:(%f,%f),半径:%f,面积:%f",c.x,c.y,c.r,c.countArea());

}

}

class Circle

{

public Circle()

{

this(0,0,0);

}

public Circle(double x,double y,double r)

{

this.x=x;

this.y=y;

this.r=r;

}

public double countArea()

{

return Math.PI*r*r;

}

/*private*/public double x,y,r;

}

求Java三角形圆形代码过程!急急急!!!

public class Test {

public static void main(String[] args) {

//三角形

Triangle t = new Triangle(3.0,4.0,5.0);

t.GetArea();

//圆形

Circle c = new Circle(5.0);

c.getArea();

}

}

class Triangle {

double x, y, z, p, s;

public Triangle(double x, double y, double z) {

this.x = x;

this.y = y;

this.z = z;

}

public void GetArea() {

if (x + y = z || x + z = y || y + z = x)

System.out.println("不能构成三角形");

else {

p = (x + y + z) / 2;

s = (double) Math.sqrt(p * (p - x) * (p - y) * (p - z));

System.out.println("三角形面积为:"+s);

}

}

}

class Circle {

double r ;

public Circle(double r){

this.r = r;

}

public void getArea() {

double S = Math.PI * r * r;

System.out.print("圆形面积为:" + S);

}

}

我建的是类部类,你移出去一样的。希望能帮到你!


网页名称:java圆排列代码 java编写一个圆类circle
文章起源:http://ybzwz.com/article/ddedgjc.html