+ 1

Why 3rd test doesnt work in Java course in 56. lesson Shape project?

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape{ Square(int x) { this.width = x; } public void area() { System.out.println(this.width*this.width); } } class Circle extends Shape { Circle(int y) { this.width = y; } public void area() { System.out.println(this.width*this.width*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(); } }

9th Mar 2022, 4:11 PM
Samuel
Samuel - avatar
3 ответов
+ 2
Try System.out.println(Math.PI*this.width*this.width) ;
9th Mar 2022, 4:15 PM
Jayakrishna 🇮🇳
+ 1
It helps, thank you.
9th Mar 2022, 4:25 PM
Samuel
Samuel - avatar
0
It works for me too, but I don't understand why!
7th Oct 2022, 8:44 PM
Zedday Christine
Zedday Christine - avatar