初学Java编程,这里对圆柱按体积排序的地方出了问题,怎么修改
package Java;public class Circle
{
int r;
Circle(int r)
{
this.r = r;
}
// 返回直径
public double getDiameter()
{
return 2 * r;
}
// 返回周长
public double getCircumference()
{
return 2 * 3.14 * r;
}
// 返回面积
public double getArea()
{
return Math.PI * r * r;
}
}
package Java;
import
import java.util.Scanner;
public class Main
{
static Cylinder cy[];
public static void main(String[] args) throws IOException
{
double data[] = new double[3];
cy = new Cylinder[3];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < cy.length; i++)
{
System.out.println("请输入圆柱的半径:");
int r = sc.nextInt();
System.out.println("请输入圆柱的高:");
int h = sc.nextInt();
cy[i] = new Cylinder(r, h);
}
for (int i = 0; i < cy.length; i++)
{
data[i] = cy[i].getVolume();
}
findCy();
sort(data);
}
public static void sort(double data[])
{
double t = 0;
for (int i = 0; i < data.length; i++)
{
for (int j = 0; j < data.length - i - 1; j++)
{
if (data[j] > data[j + 1])
{
t = data[j];
data[j] = data[j + 1];
data[j + 1] = t;
}
}
}
System.out.println("排序结果为");
for (int i = 0; i < data.length; i++)
{
System.out.println(data[i]);
}
}
public static void findCy()
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入要查找的高");
int h = sc.nextInt();
System.out.println("请输入要查找的半径:");
int r = sc.nextInt();
boolean flag = false;
for (int i = 0; i < cy.length; i++)
{
if (r == cy[i].getr() && h == cy[i].getHeight())
{
System.out.println("第" + (i +1)+ "个圆柱满足条件");
flag = true;
}
}
if (flag == false)
{
System.out.println("没有找到这样的圆柱");
}
}
}