class Cycle
{
private double radius;
public Cycle(double radius)
{
this.radius=radius;
}
public Cycle compare(Cycle c)
{
//程序代码
return (this.radius>c.radius) ? this : c ;
}
}
class TD
{
public static void main(String[] args)
{
Cycle c1=new Cycle(1.0);
Cycle c2=new Cycle(2.0);
Cycle c;
c=c1.compare(c2);
if(c==c1)
System.out.println("圆1的面积比较大");
else
System.out.println("圆2的面积比较大");
}
}
------解决方案--------------------
- Java code
class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public Circle compare(Circle c) { // 程序代码 return (this.radius > c.radius) ? this : c; }}class TD { public static void main(String[] args) { Circle c1 = new Circle(1.0); Circle c2 = new Circle(2.0); Circle c; c = c1.compare(c2); if (c == c1) System.out.println("圆1的面积比较大"); else System.out.println("圆2的面积比较大"); }}
------解决方案--------------------
对,不必加其实也可以,目测楼主是不是吧文件名写错了
------解决方案--------------------
我晕,我在 自己的eclipse上面运行,木有错误啊
结果是:圆2的面积比较大
- Java code
package com;public class Cycle { private double radius; public Cycle(double radius) { this.radius=radius; } public Cycle compare(Cycle c) { //程序代码 return (this.radius>c.radius) ? this : c ; }}
------解决方案--------------------