import java.util.Scanner; abstract class Shape{ abstract float GetArea(); abstract float GetPerimeter(); } class Rectangle{ private double x,y; public Rectangle(int i, int j) { x=i; y=j; } public float GetArea(){ return (float)(x*y); } public float GetPerimeter(){ return (float)((x+y)*2) ; } //write code here } class Circle{ private double a; public Circle(int i) { a=i; } public float GetArea(){ return (float)(a*3.14*a); } public float GetPerimeter(){ return (float)(3.14*2*a); } //write code here } public class Main{ public static void main(String[] args){ Scanner sca = new Scanner(System.in); int a = sca.nextInt(); int b = sca.nextInt(); int r = sca.nextInt(); Rectangle aa = new Rectangle(a,b); System.out.println(aa.GetArea()); System.out.println(aa.GetPerimeter()); Circle c = new Circle(r); System.out.println(c.GetArea()); System.out.println(c.GetPerimeter()); } }
时间: 2025-01-02 09:29:15