+ 1
this code is not working properly in the code project of 'more on classes'
import java.util.Scanner; import java.lang.Math; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape{ Square(int wid){ width = wid; } void area(){ System.out.println(width*width); } } class Circle extends Shape{ Circle(int rad){ width = rad; } void area(){ System.out.println(Math.PI*width*width); } } public class Main{ public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); Square a = new Square(x); Circle b = new Circle(y); a.area(); b.area(); } }
3 odpowiedzi
+ 3
Ancient Lynx
I ran your code and all the test cases are passed 🤔
https://code.sololearn.com/c7B0C1G9dAyr/?ref=app
+ 2
Use Math.PI instead of 3.141592654
0
But still in the last case, i think the output didn't match!