sortingshapes.java
来自「Java程序设计技巧与开发实例附书源代码。」· Java 代码 · 共 37 行
JAVA
37 行
public class SortingShapes
{
public static void showShapes(String title, Shape shapes[])
{
System.out.println(title);
for (int i = 0; i < shapes.length; i++)
{
System.out.println(shapes[i]);
}
}
public static void main(String args[])
{
Rectangle r[] =
{
new Rectangle(2, 6),
new Rectangle(3, 3), new Rectangle(1, 4)};
Circle c[] =
{
new Circle(3), new Circle(2), new Circle(1)};
for (int i = 0; i < r.length; i++)
{
r[i].computeArea();
r[i].computePerimeter();
c[i].computeArea();
c[i].computePerimeter();
}
showShapes("Unsorted Rectangles", r);
Sorter.sort(r);
showShapes("Sorted Rectangles", r);
showShapes("Unsorted Circles", c);
Sorter.sort(c);
showShapes("Sorted Circles", c);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?