들여쓰기 수정 완료
매개변수가 1개인 메서드 3개
1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
//호출
UseSkill(3);
}
//정의
static void UseSkill(int n)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine("스킬을 사용합니다.");
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
//호출
UsePotion(3);
}
//정의
static void UsePotion(int n)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine("물약을 사용합니다.");
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
3.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
//호출
Defense(3);
}
//정의
static void Defense(int n)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine("방어합니다.");
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
매개변수가 2개인 메서드 3개
4.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
//호출
UseHeal("힐", 3);
}
//정의
static void UseHeal(string skillName, int n)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine("{0}을 사용합니다.", skillName);
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
5.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
//호출
CriticalAttack("치명타 공격", 5);
}
//정의
static void CriticalAttack(string action, int n)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine("{0}을 합니다.", action);
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
6.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
//호출
Jump("점프", 5);
}
//정의
static void Jump(string action, int n)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine("{0}을(를) 합니다.", action);
}
}
}
}
'C# > 수업 내용' 카테고리의 다른 글
메서드와 지역변수, 전역변수 복습 (0) | 2021.12.23 |
---|---|
반환값은 없고 매개변수가 있는 메서드 연습 (0) | 2021.12.23 |
메서드 정의하고 호출하기 5번연습 (0) | 2021.12.23 |
ReadKey()와 ConsoleKeyInfo 그리고 if문 (0) | 2021.12.23 |
for문 연습문제 복습 (0) | 2021.12.23 |