+ 1

Where did I go wrong?

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } class Square extends Shape{ public void area(int width){ area = width*width; System.out.println(area); } } class Circle extends Shape{ public void area(int width){ area = Math.PI*(width*width); System.out.println(area); } } public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); Shape a = new Square(x); Shape b = new Circle(y); a.area(); b.area(); } } Output (to be) Sample Input: 5 2 Sample Output: 25 12.566370614359172

3rd Oct 2022, 4:28 PM
Bettina Helen R
1 Antwort
+ 2
Bettina Helen R Remove ( ) just write Math.PI * width * width
3rd Oct 2022, 4:29 PM
A͢J
A͢J - avatar