0

What is wrong in my code,i want output of area of circle in fraction

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } class Circle extends Shape { double pi = 3.14, ar; public Circle(int w){ this.width = w; } @Override public void area() { //super.area(); ar = pi * this.width * this.width; System.out.println("Area of circle:"+ar); } } class Square extends Shape { int ar; public Square(int w){ this.width = w; } @Override public void area() { //super.area (); ar = this.width * this.width; System.out.println("Area of Square :"+ar); } } 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 Apr 2021, 11:44 AM
mangesh choudhari
mangesh choudhari - avatar
2 Antworten
0
Your code is correct and working without error in sololearn u can to give all inputs at a time
13th Apr 2021, 12:08 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
try to Use Math.PI instead of pi..
13th Apr 2021, 9:02 PM
Jayakrishna 🇮🇳