请问这两道题怎么编!谢谢

2024-12-30 04:42:11
推荐回答(2个)
回答1:

不要放在一个文件里,一个class一个文件.
public abstract class Shape {
public abstract double GetArea();
}
public class Rectangle extends Shape {

private double w;

private double h;

public Rectangle(double w, double h) {
this.w = w;
this.h = h;
}

public double getH() {
return h;
}

public void setH(double h) {
this.h = h;
}

public double getW() {
return w;
}

public void setW(double w) {
this.w = w;
}

public double GetArea() {
return w * h;
}
}
public class Circle extends Shape {

private double r;

public Circle(double r) {
this.r = r;
}

public double getR() {
return r;
}

public void setR(double r) {
this.r = r;
}

public double GetArea() {
return Math.PI * r * r;
}
}
public class Admin {

public static void main(String[] args) {
Rectangle r = new Rectangle(200, 100);
System.out.println(r.GetArea());

Circle c = new Circle(200);
System.out.println(c.GetArea());
}
}
那就只保留Admin 前面的public .其他的public 全去掉

回答2:

#include

int
main()
{
int
i,j,a[5],b[5],min,tmp;
for(i=0;i<5;i++)
//读入数组a,同时初始化数组b
{
scanf("%d",&a[i]);
b[i]
=
i;
}
for(i=0;i<5;i++)
{
min
=
i;
for(j=i+1;j<5;j++)
{
if(a[b[j]]
<
a[b[min]])
{
min
=
j;
}
}
if(min!=i)
{
tmp
=
b[min];
b[min]
=
b[i];
b[i]
=
tmp;
}
}
for(i=0;i<5;i++)
{
printf("%d
",a[i]);
}
printf("\n");
for(i=0;i<5;i++)
{
printf("%d
",b[i]);
}
return
0;
}