Computer Science, asked by jalanshruti1978, 1 day ago

import java.util;
class area
{
public static void main (String Args[])
{
Scanner Sc= new Scanner(System.in);
int r,h;
double a1,a2;
Sphere = ("22/7*Math.pow"(r,2));
Cylinder = ("2*22/7*Math.pow"(r,2)*h);
System.out.println("Area of the sphere is " + area);
System.out.println("Area of the cylinder is " + area);
}
}
}
please can anyone tell is any error there in this program

Answers

Answered by simonsaikia9
0

Here is your correct answer:

import java.util.Scanner;

class area {

   public static void main(String Args[]) {

       Scanner sc = new Scanner(System.in);

       double r1, r2, h;

       // Taking input from the user about radius of the sphere

       System.out.print("Enter radius of the sphere: ");

       r1 = sc.nextDouble();

       // calculating area of the sphere

       double sphere = 4 * Math.PI * Math.pow(r1, 2);

       // displaying the area of the sphere

       System.out.format("Area of the sphere is: %.2f \n", sphere);

       // Taking input from the user about radius and height of the cylinder

       System.out.print("Enter radius of the cylinder: ");

       r2 = sc.nextDouble();

       System.out.print("Enter the height of the cylinder: ");

       h = sc.nextDouble();

       // calculating area of the cylinder

       double cylinder = 2 * Math.PI * r2 * (r2 + h);

       // displaying the area of the cylinder

       System.out.format("Area of the cylinder is: %.2f \n", cylinder);

   }

}

There were lots of errors. eg:

1. you have declared sphere and cylinder variables

2. you are printing area but there was no variable declared with that name

3. Some mistakes you have done, such as declaring a1 and a2 but you didn't used any of them and same goes to sc object,

4. One more error, you are double quotes in mathematical expression in line 9 and 10.

And the formula was also wrong

Similar questions