- 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

28th Feb 2021, 1:31 AM
Itzel Medina
Itzel Medina - avatar
3 Answers
+ 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(); } }
28th Feb 2021, 2:16 AM
Petros the Parakeet
Petros the Parakeet - avatar
+ 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); } }
28th Feb 2021, 2:04 AM
Petros the Parakeet
Petros the Parakeet - avatar
+ 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 馃槉
28th Feb 2021, 2:24 AM
Itzel Medina
Itzel Medina - avatar