0

What is causing for getting failed in test case 3?

import java.util.Scanner; class Square { public void width(int x) { System.out.println((int)Math.pow(x,2)); } } class Circle { public void width(int x) { System.out.println(x*x*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(); Circle b = new Circle(); a.width(x); b.width(y); You need to create two Shape subclasses, Square and Circle, which initialize the width attribute using their constructor, and define their area() methods. The area() for the Square class should output the area of the square (the square of the width), while for the Circle, it should output the area of the given circle (PI*width*width). The code in main creates two objects with the given user input and calls the area() methods. Sample Input: 5 2 Sample Output: 25 12.566370614359172

13th Jul 2021, 12:06 AM
Shahir
Shahir - avatar
4 Respuestas
+ 1
Shaik.Shahir Change (x * x * Math.PI) to (Math.PI * x * x)
13th Jul 2021, 4:29 AM
A͢J
A͢J - avatar
+ 1
Hoo! Got it
13th Jul 2021, 4:58 AM
Shahir
Shahir - avatar
0
Thanks! It works But I have a doubt: What makes the difference between x*x*math.PI and math.PI*x*x Though I am getting the same output in both cases
13th Jul 2021, 4:45 AM
Shahir
Shahir - avatar
0
Shaik.Shahir No there will be minor difference like 0.000000001
13th Jul 2021, 4:56 AM
A͢J
A͢J - avatar