Practice: Methods
Fill in the missing blanks to create a method that calculates the area of a circle and returns the value.
index
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
public class ConsoleApp
{
class Point {
public double x;
public double y;
}
class Circle {
public double radius;
public Point center;
___ ___ ___() {
// The formula is: pi . r . r
// The value of pi is 3.14
// r is the radius
___ ___ * ___* radius;
}
}
public static void Main(string[] args)
{
Point p = new Point();
p.x = 15;
p.y = 15;
Circle circle = new Circle();
circle.radius = 10;
circle.center = p;
Console.WriteLine($"Area of the circle with center at ({circle.center.x}, {circle.center.y}) and radius of {circle.radius} is {circle.area()}");
}
}
123456789101112131415161718192021222324252627282930313233using System; public class ConsoleApp { class Point { public double x; public double y; } class Circle { public double radius; public Point center; ___ ___ ___() { // The formula is: pi . r . r // The value of pi is 3.14 // r is the radius ___ ___ * ___* radius; } } public static void Main(string[] args) { Point p = new Point(); p.x = 15; p.y = 15; Circle circle = new Circle(); circle.radius = 10; circle.center = p; Console.WriteLine($"Area of the circle with center at ({circle.center.x}, {circle.center.y}) and radius of {circle.radius} is {circle.area()}"); } }
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 8
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione