package com.itheima;
//接口实现 从键盘输入数字,求园的周长和面积
public interface inter_2 {
final double pi=3.1415925; //接口中的 数字 final 必须加上,不加 系统也会自动加下
abstract double getArea(double r);//接口中的方法 必须加上abstract
abstract double getcir(double r);
}
package com.itheima;
public interface inter_show {
abstract void show(int r);
}
package com.itheima;
import java.util.Scanner;
public class inter_3 implements inter_2,inter_show{
private int r;
public inter_3(){
}
public inter_3(int r){
this.r=r;
}
public static void main(String args[])
{
System.out.println("请输入你要求圆的半径");
inter_3 a=new inter_3();
Scanner sc=new Scanner(System.in);
a.r=sc.nextInt();
double b=a.getArea(a.r);
double c=a.getcir(a.r);
System.out.println("周长为"+c+"面积为"+b);
a.show(a.r);
}
public double getArea(double r){
return pi*r*r;
}
public double getcir(double r){
return 2*pi*r;
}
public void show(int r){
System.out.println("圆面积为"+(pi*r*r));
System.out.println("圆周长为"+(2*pi*r));
}
}
|