0
What's wrong
I want model three circles and to calculte it's area & perimeter. What's wrong this code? public class Circle{ private double r1; private double r2; private double r3; public double Circle(double r1,double r2,double r3){ this.r1=r1; this.r2=r2; this.r3=r3; } public double Mypro(){ Circle r1=new Circle(); Circle r2=new Circle(); Circle r3=new Circle(); r1.r1=9.2; r2.r2=3; r3.r3=6; } public static double getArea(double r){ return r*r*3.14; } public static double getPerimeter(double r){ return 2*r*3.14; } public static void main(String[] args){ System.out.println("Area:"+ getArea(r1) + " "); System.out.println("Perimeter:"+ getPerimeter(r1) + " "); } }
2 Réponses
+ 4
3axpa
Why there are 3r even 1r is enough to do the job.
You should take r as an input
what is the use of method 'Mypro' and why it has return type 'double'
r1 is non-static so you can't access in main method
you have created object with same name of variables so r1.r1 is a valid?
Constructor can't have return type.
https://code.sololearn.com/cOVld6T6k6BY/?ref=app
+ 1
Tnx for help me