I can't pass hidden test. What's the problem? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I can't pass hidden test. What's the problem?

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } public class Square extends Shape { public Square (int w) { width = w; } @Override public void area() { System.out.println(width * width); } }; public class Circle extends Shape { public Circle (int w) { width = w; } @Override public void area() { System.out.println(Math.pow(width, 2) * Math.PI); } }; 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(); } }

13th Dec 2020, 7:07 PM
1sses
1sses - avatar
1 Answer
+ 2
I rewrite the code and solve the problem. Still don't understand why it didn't work... import java.util.Scanner; abstract class Shape { int width; abstract void area(); } class Square extends Shape { Square (int w) { width = w; } @Override public void area() { int area = width * width; System.out.println(area); } }; class Circle extends Shape { Circle (int w) { width = w; } @Override public void area() { double area = Math.PI * width * width; System.out.println(area); } }; 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(); } }
13th Dec 2020, 7:27 PM
1sses
1sses - avatar