비교 연산자, if문, for문
using System;
namespace LearnDotnet
{
internal class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
bool isSelectTerran = input == "테란";
Console.WriteLine("테란을 선택했습니까? {0}", isSelectTerran);
int hp = 10;
int monsterDamage = 11;
hp -= monsterDamage;
bool isDead = hp <= 0;
Console.WriteLine("isDead: {0}", isDead);
}
}
}
if문
if(부울 식){
}
for문
1번
using System;
namespace LearnDotnet
{
internal class Program
{
static void Main(string[] args)
{
for(int i=0; i<5; i++)
{
Console.WriteLine("줄넘기를 했습니다.");
}
}
}
}
2번
using System;
namespace LearnDotnet
{
internal class Program
{
static void Main(string[] args)
{
for(int i=0; i<4; i++)
{
Console.WriteLine("줄넘기를 {0}회 했습니다.",i+1);
}
}
}
}
3번
using System;
namespace LearnDotnet
{
internal class Program
{
static void Main(string[] args)
{
int num = 0;
for(int i=0; i<3; i++)
{
Console.WriteLine("쌩쌩이를 했습니다.");
// i++;
num = (i+1)*2;
}
Console.WriteLine("-------------------------");
Console.WriteLine("줄넘기를 총 {0}회 했습니다.",num);
}
}
}
4번
using System;
namespace LearnDotnet
{
internal class Program
{
static void Main(string[] args)
{
int num = 0;
for(int i=0; i<9; i++)
{
Console.WriteLine("2 x {0} = {1}",i+1,2*(i+1));
}
}
}
}
'C# 기초' 카테고리의 다른 글
switch문, 생성자 연습+예제 (0) | 2023.07.21 |
---|---|
for문 연습문제 나머지(5~14)+도전문제 (0) | 2023.07.20 |
input, enum의 활용, 값 형식,참조 형식, Boxing,산술연산 (0) | 2023.07.20 |
var, const, 열거형 (0) | 2023.07.20 |
스타크래프트 (0) | 2023.07.19 |