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) + " "); } }

12th Mar 2023, 6:35 PM
3axpa
3axpa - avatar
2 Antworten
+ 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
12th Mar 2023, 7:01 PM
A͢J
A͢J - avatar
+ 1
Tnx for help me
13th Mar 2023, 2:12 PM
3axpa
3axpa - avatar