1. 벌쳐 마인설치
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
const int MAX = 3;
static int mineCount = 3;
static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine(InstallMine());
}
}
static bool InstallMine()
{
if (mineCount > 0)
{
mineCount--;
Console.WriteLine("설치했습니다. 마인의 개수 {0}/{1}", mineCount, MAX);
return true;
}
else
{
Console.WriteLine("남은 마인이 없습니다.");
return false;
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
2. 템플러 합체
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static string unit1 = "하이템플러";
static string unit2 = "다크템플러";
static void Main(string[] args)
{
Console.WriteLine("결과: {0}", FusionTemplers(unit1, unit1));
Console.WriteLine("결과: {0}", FusionTemplers(unit2, unit2));
Console.WriteLine("결과: {0}", FusionTemplers(unit1, unit2));
Console.WriteLine("결과: {0}", FusionTemplers(unit2, unit1));
Console.WriteLine("결과: {0}", FusionTemplers(unit1, unit1));
}
static string FusionTemplers(string name1, string name2)
{
if (name1 == name2 && name1 == unit1)
{
Console.WriteLine("합체합니다.");
return "아콘";
}
else if (name1 == name2 && name1 == unit2)
{
Console.WriteLine("합체합니다.");
return "다크아콘";
}
else
{
Console.WriteLine("불가능합니다.");
return null;
}
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
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)
{
Random rand = new Random();
for (int i = 0; i < 10; i++)
{
int num = rand.Next(0, 10);
Console.WriteLine("{0}입니다.", judgment(num));
}
}
static string judgment(int number)
{
if (number == 0)
{
Console.WriteLine("난수 발생: {0}", number);
return "오류";
}
else if (number % 2 == 0)
{
Console.WriteLine("난수 발생: {0}", number);
return "짝수";
}
else
{
Console.WriteLine("난수 발생: {0}", number);
return "홀수";
}
}
}
}
난수생성도 복습.
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
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)
{
Console.Write("숫자를 입력하세요 : ");
int inputNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("카운트 : {0}", Roap(inputNumber));
}
static int Roap(int n)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine("줄넘기를 했습니다.");
}
return n / 2;
}
}
}
'C# > 수업 내용' 카테고리의 다른 글
클래스 만들기-생성자 메서드 (라바-드론 생산) (0) | 2021.12.23 |
---|---|
계산기 메서드 만들어보기 (0) | 2021.12.23 |
메서드와 지역변수, 전역변수 복습 (0) | 2021.12.23 |
반환값은 없고 매개변수가 있는 메서드 연습 (0) | 2021.12.23 |
반환값이 없고 매개변수가 있는 메서드 정의 및 호출 (0) | 2021.12.23 |