My program calculates the surface area of a cone (pi * radius * slant-height
). I'm using an if-elseif
ladder which says that if the slant-height is left empty and the vertical-height is entered, the program will calculate the slant-height via Pythagoras theorem. But I don't know how to make the program accept a null value
I tried using if(slant_height==null)
but it says that the types are incompatible and ==
is a "bad operator type"
{
public void CSAcone(double radius,double slant_height,double height) {
if (slant_height == null)
{
slant_height=Math.sqrt((radius*radius) + (height*height));
double CSA=(22*radius*slant_height) / 7;
System.out.println("radius= "+radius);
System.out .println("height= "+slant_height);
System.out .println("Curved Suface Area= "+CSA);
}
if(height == null)
{
double CSA=(22*radius*slant_height) / 7;
System.out.println("radius= " + radius);
System.out.println("height= " + slant_height);
System.out.println("Curved Suface Area= " + CSA);
}
}}