0

why one from five tests of this code outputs error? (More on classes - 56 Code project)

import java.util.Scanner; abstract class Shape { int width; abstract void area(); Shape (int w) { this.width = w; } } public class Square extends Shape { Square (int w) { super(w); } void area () { System.out.println(width*width); } } public class Circle extends Shape { Circle (int w) { super(w); } void area () { System.out.println((double)(width*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(); } }

11th Jul 2021, 9:29 AM
Сергей Владимирович
Сергей Владимирович - avatar
1 Antwort
0
Try this : void area () { System.out.println((double)width*width*Math.PI); } Or void area () { System.out.println(Math.PI*width*width); }
11th Jul 2021, 6:05 PM
Jayakrishna 🇮🇳