Challenge: Methods Creation
Following is a code for outputting a triangle shape using multiple Console.WriteLine
statements:
main.cs
12345Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*");
Create a new method called displayTriangle
with the above code and call it in the main function.
main.cs
123456789101112131415using System; namespace ConsoleApp { internal class Program { // Create a method here static void Main(string[] args) { // Call the function here } } }
Create a method using static void methodName()
syntax and put the triangle code inside it.
Afterwards, execute it in the main method.
main.cs
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(); } } }
Tack för dina kommentarer!
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 1.59
Challenge: Methods Creation
Svep för att visa menyn
Following is a code for outputting a triangle shape using multiple Console.WriteLine
statements:
main.cs
12345Console.WriteLine("*********"); Console.WriteLine("*******"); Console.WriteLine("*****"); Console.WriteLine("***"); Console.WriteLine("*");
Create a new method called displayTriangle
with the above code and call it in the main function.
main.cs
123456789101112131415using System; namespace ConsoleApp { internal class Program { // Create a method here static void Main(string[] args) { // Call the function here } } }
Create a method using static void methodName()
syntax and put the triangle code inside it.
Afterwards, execute it in the main method.
main.cs
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(); } } }
Tack för dina kommentarer!