Практика створення методів
Нижче наведено код для виведення форми трикутника за допомогою кількох операторів Console.WriteLine
:
main
9
1
2
3
4
5
Console.WriteLine("*********");
Console.WriteLine("*******");
Console.WriteLine("*****");
Console.WriteLine("***");
Console.WriteLine("*");
12345Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*");
Створіть новий метод під назвою displayTriangle
з наведеним вище кодом і викличте його в основній функції.
main
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
namespace ConsoleApp
{
internal class Program
{
// Create a method here
static void Main(string[] args)
{
// Call the function here
}
}
}
123456789101112131415using System; namespace ConsoleApp { internal class Program { // Create a method here static void Main(string[] args) { // Call the function here } } }
Створіть метод, використовуючи синтаксис static void
methodName()
, і помістіть код трикутника всередину нього.
Потім виконайте його в основному методі.
main
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
namespace ConsoleApp
{
internal class Program
{
// Create a method here
static void displayTriangle()
{
Console.WriteLine("*********");
Console.WriteLine("*******");
Console.WriteLine("*****");
Console.WriteLine("***");
Console.WriteLine("*");
}
static void Main(string[] args)
{
// Call the method here
displayTriangle();
}
}
}
1234567891011121314151617181920212223using System; namespace ConsoleApp { internal class Program { // Create a method here static void displayTriangle() { Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*"); } static void Main(string[] args) { // Call the method here displayTriangle(); } } }
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 6. Розділ 3
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат