第一題
public class circle {
private double r;
public double showArea(double r){
return 3.14*r*r;
}
public double showPerimeter(double r){
return r*3.14*2;
}
public double getR(){
return r;
}
public void setR(double r){
this.r=r;
}
}
public class test {
public static void main(String[] args) {
circle circle=new circle();
System.out.println("面積為"+circle.showArea(8));
System.out.println("周長為"+circle.showPerimeter(8));
}
}
第二題
public class MyDate {
int n;
int y;
int r;
MyDate(int n, int y, int r) {
this.n = n;
this.y = y;
this.r = r;
}
public void showDate() {
System.out.println("日期:" + n + "年" + y + "月" + r + "日");
}
public void isBi() {
if ((n % 4 == 0) && (n % 10 != 0) || (n % 400 == 0)) {
System.out.println(n + "年是閏年");
} else {
System.out.println(n + "年不是閏年");
}
}
}
public class Testmydate {
public static void main(String[] args) {
MyDate date = new MyDate(1900,1,1);
date.showDate();
date.isBi();
}
}