小菜鸟进化
2019-04-02 16:59
package Shape;
public abstract class Shape {
public abstract void mianji();
public abstract void zhouchang();
}
package Shape;
import java.util.Scanner;
public class Rectangle extends Shape {
Scanner in=new Scanner(System.in);
int windth=in.nextInt();
int length=in.nextInt();
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("矩形的面积为:"+windth*length);
}
@Override
public void zhouchang() {
// TODO Auto-generated method stub
System.out.println("矩形的周长为:"+(windth+length)*2);
}
}
package Shape;
import java.util.Scanner;
public class Circle extends Shape {
Scanner in=new Scanner(System.in);
double Radius=in.nextDouble();
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("圆的面积为:"+Math.PI*Radius*Radius);
}
@Override
public void zhouchang() {
// TODO Auto-generated method stub
System.out.println("圆的面积为:"+2*Math.PI*Radius);
}
}
package Shape;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入宽和高:");
Shape juxing=new Rectangle();
juxing.mianji();
juxing.zhouchang();
System.out.println("请输入半径:");
Shape yuan=new Circle();
yuan.mianji();
yuan.zhouchang();
}
}
你这个Math.PI就这样可以直接使用吗?不需要导入包或者声明一下吗?
不错,学的很稳
老铁可以
厉害厉害
喔。Math.PI是π啊
厉害 我都忘了第一季的输入输出了
呃呃呃
Java入门第二季 升级版
530653 学习 · 6091 问题
相似问题