+ 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(); } }

26th Dec 2021, 2:48 PM
Annesh Lobdha Singh
Annesh Lobdha Singh - avatar
3 Respuestas
+ 3
Ancient Lynx I ran your code and all the test cases are passed 🤔 https://code.sololearn.com/c7B0C1G9dAyr/?ref=app
26th Dec 2021, 3:02 PM
Atul
Atul - avatar
+ 2
Use Math.PI instead of 3.141592654
26th Dec 2021, 2:53 PM
Atul
Atul - avatar
0
But still in the last case, i think the output didn't match!
26th Dec 2021, 2:58 PM
Annesh Lobdha Singh
Annesh Lobdha Singh - avatar