JAVA定义类证明两圆是同心圆的程序全码。。
发布网友
发布时间:2023-03-23 01:05
我来回答
共2个回答
热心网友
时间:2023-10-12 20:08
class Circle {
public int x;//圆心的x坐标
public int y;//圆心的y坐标
public int r;//圆的半径
public Circle(int x, int y, int r) {
this.x = x;
this.y = y;
this.r = r;
}
}
public class Test {
public static void main(String[] args) {
Circle c1 = new Circle(1, 2, 2);
Circle c2 = new Circle(1, 2, 4);
Circle c3 = new Circle(2, 2, 2);
if(check(c1,c2)) System.out.println("c1和c2是同心圆");
else System.out.println("c1和c2不是同心圆");
}
static boolean check(Circle c1, Circle c2) {
if(c1.x == c2.x && c1.y == c2.y) return true;//圆心相同就是同心圆
else return false;
}
}
热心网友
时间:2023-10-12 20:09
class round
{int[] point;
int size;
public round(int x,int y,int size)
{
this.point[0]=x;
this.point[1]=y;
this.size=size;}
public int checked(round temp)
{if(temp.point[0]==this.point[0]&&temp.point[1]==this.point[1])
if(temp.size==this.size)return 2;
else return 1;
else return 0;
}
}
public class a
{
public static void main(String args[])
{
round x1=new round(1,2,3);
round x2=new round(1,2,5);
if(x1.checked(x2)==1)
System.out.println("是同心圆");
else if(x1.checked(x2)==2)
System.out.println("两圆是相同的");
else if(x1.checked(x2)==0)
System.out.println("两圆没有任何关系");
}
}