Forms | Sololearn: Learn to code for FREE!

-1

Forms

Hi! Someone knows what's wrong with my code? For some reason it doesn't work in case 3 but I already run it on my computer and I don't see any problem https://code.sololearn.com/co4kai0X354f/?ref=app

2/28/2021 1:31:54 AM

Itzel Medina

3 Answers

New Answer

+8

Itzel Medina de esta manera funciona: import java.util.Scanner; //import java.lang.System.*; abstract class Shape { int width; abstract void area(); } //tu código va aquí public class Square extends Shape { Square(int width) { this.width = width; } public void area() { System.out.println(width * width); } } public class Circle extends Shape { Circle(int width) { this.width = width; } public void area() { double pi = Math.PI; System.out.println(pi * width * width); } } public class Program { 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(); } }

+4

Puede que el problema sea con la clase circle al momento de hacer el cálculo... Intenta así: public class Circle extends Shape { Circle(int width) { this.width = width; } public void area() { double pi = Math.PI; System.out.println(pi * width * width); } }

+2

Gracias! Si funcionó, aunque no me quedó muy claro en qué había fallado mi código, supongo que debi poner la operación en el system.out? Igual gracias 😊