Write code which takes a double input from the user and creates a circle with that radius. The code should calculate the area of the circle, then double the radius of the circle and print the new area of the circle. Sample run: Enter radius: > 2.0 Area: 12.566370614359172 Radius is being doubled... Area: 50.26548245743669

Answer :

jsaada

Answer:import java.util.Scanner;

import (*software used for shapes*);

public class (*enter class name*){

 public static void main(String[] args){

 

   Scanner scan = new Scanner(System.in);

   System.out.println("Enter radius: ");

   double r = scan.nextDouble();  

   Circle c = new Circle(r);

   double area = c.getArea();  

   System.out.println("Area: "+area);

   System.out.println("Radius is being doubled...");  

   r = c.getRadius();  

   c.setRadius(r*2);

   area = c.getArea();

   System.out.println("Area: "+area);

 

Explanation:

I know this is late, but I am putting this here for future people trying to solve this problem.

The C code is given by:

void areaCircle(double r){

      double A;

      A = pi*r*r;

      printf("Area: %lf\n", A);

      r *= 2;

      A = pi*r*r;

      printf("Radius is being doubled \n");

      printf("Area: %lf\n", A);

}

The input is taken in:

int main(){

      double r;

      scanf("%lf\n", &r);

       return 0;

}

--------------------

The function is declared as void, as it does not return anything, and has the radius as input, thus:

void areaCircle(double r){

}

The area is [tex]A = \pi r^2[/tex], thus, inserting and printing in the code.

void areaCircle(double r){

      double A;

      A = pi*r*r;

      printf("Area: %lf\n", A);

}

Doubling the radius and printing the new area, the complete code is:

void areaCircle(double r){

      double A;

      A = pi*r*r;

      printf("Area: %lf\n", A);

      r *= 2;

      A = pi*r*r;

      printf("Radius is being doubled \n");

      printf("Area: %lf\n", A);

}

As for the input:

int main(){

      double r;

      scanf("%lf\n", &r);

       return 0;

}

A similar problem is given at https://brainly.com/question/14316064

Other Questions