C#/수업 내용

[C#] Random

JSH1 2021. 8. 20. 12:05
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            Random rand = new Random(); 
            int num = rand.Next(1, 6+1);    //1~6개 까지의 난수를 생성

            //만약에 임의의 값이 5보다 같거나 크면 강화성공을 출력하고
            //그렇지 않다면 강화실패를 출력한다
            if(num>=5)
            {
                Console.WriteLine(num);
                Console.WriteLine("강화 성공");
            }
            else
            {
                Console.WriteLine(num);
                Console.WriteLine("강화 실패");
            }
        }
    }
}


 

'C# > 수업 내용' 카테고리의 다른 글

[C#] for, foreach  (0) 2021.08.20
2021-08-20 오전  (0) 2021.08.20
2021-08-19 연습문제  (0) 2021.08.19
[C#] else if  (0) 2021.08.19
[C#] if  (0) 2021.08.19