import java.util.Scanner; public class Test_4 {     public static void main(String[]args) {         Shape[] shs={new Square(),new Circle()};         Scanner sc=new Scanner(System.in);         double temp;         String st="数据不合理,无法计算";                  System.out.print("请输入正方形边长:");         temp=sc.nextDouble();         System.out.println(isReasonable(temp)?"正方形面积为:"+shs[0].area(temp):st);                  System.out.print("\n请输入圆形半径:");         temp=sc.nextDouble();         System.out.println(isReasonable(temp)?"圆形面积为:"+shs[1].area(temp):st);     }     public static boolean isReasonable(double temp) {         if(temp<=0) {             return false;         }else {             return true;         }     } } interface Shape{     double area(double temp); } class Square implements Shape{     public double area(double temp) {         return temp*temp;     } } class Circle implements Shape{     public double area(double temp) {         return Math.pow(temp, 2)*Math.PI;     } }
点赞 评论

相关推荐

牛客83265014...:完了,连现在都没开始面,13号投的是不是晚了
秋招的第一个offer,...
点赞 评论 收藏
分享
ResourceUt...:楼主有自己的垃圾箱,公司也有自己的人才库
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务