0

Lesson 56 ,Java ,Shape , test 3 failure

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { Square (int width ){ super.width = width ; } void area(){ System.out.println(width *width); } } class Circle extends Shape { Circle (int width ){ super.width = width ; } void area(){ System.out.println(Math.PI * Math.pow(width,2)); } } 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(); } }

15th Apr 2022, 6:01 PM
Krishna Pal Sendhav
Krishna Pal Sendhav - avatar
3 Antworten
+ 2
Rounding error. Do Math.PI * width first. I.e. replace Math.PI * Math.pow(width, 2) with Math.PI * width * width
15th Apr 2022, 6:07 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
Thank u very much Ani Jona 🕊 This help me lot
15th Apr 2022, 6:12 PM
Krishna Pal Sendhav
Krishna Pal Sendhav - avatar
+ 1
You're welcome :)
15th Apr 2022, 6:13 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar