I'm trying to calculate the length of an arc within a constructor, but when the code runs , it gives wrong output, the wrong output means the "tita" valueis set to 0.0 , when i run the code. Also i need to know why we create constructors?
I've tried modifying the code and it gives modified output only.
import java.util.*;
class Circle {
static double radius;
static int angle;
public void circumference(double radius) {
this.radius=radius;
double pi=3.14;
double circum=(2*pi)*this.radius;
System.out.println("Circumference is "+circum);
}
Circle(int angl,double rad) {
if(angl==90) {
double pi=3.14;
double tita=angl/360;
System.out.println("tita is "+tita);
double arclen=((2*pi)*rad)*tita;
System.out.println("arc length is "+arclen);
}
}
}
class Circledemo {
public static void main(String args[]) {
Scanner scan=new Scanner(System.in);
System.out.print("enter the radius: ");
double radius=scan.nextDouble();
System.out.print("enter the angle: ");
int ang=scan.nextInt();
Circle desi=new Circle(ang,radius);
desi.circumference(radius);
}
}
I expect my code to give the correctly divided value but not as 0.0