Java shape class not mark passed | Sololearn: Learn to code for FREE!


Java shape class not mark passed

My programme all test cases passed. But its not marking as a passed the test. Showing try again. Please any suggestions import java.util.Scanner; abstract class Shape { int width; public abstract void area(); } //your code goes here class Circle extends Shape{ Circle (int width ){this.width =width;} public void area (){ double area = width * width * Math.PI; System.out.println(area ); } } class Square extends Shape{ Square (int width){ this.width =width; } public void area(){ int area = width * width; System .out.println(area); } } public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(; int x = sc.nextInt(); int y = sc.nextInt(); Square a = new Square (x); Circle b = new Circle(y); a.area(); b.area(); } }

12/20/2020 1:33:28 PM

Gayan Suranga

4 Answers

New Answer


Gayan Suranga , maybe it is accuracy problem. I tried your code and changed the order for calculation of the circle's area this way => double area = Math.PI * width * width. All tests passed.


Yes you are correct problem is an order of the Math.PI function


Hey but why the order of writing terms for multiplication matters?


Shubham Bawner i think java first priority is for package if not problrm is sololearn compiler