C#/수업 내용

[C#] for, foreach

JSH1 2021. 8. 20. 13:07
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)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Hello World!");
            }
        }
    }
}


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)
        {
            int count = 0;

            for (int i = 0; i < 5; i++)
            {
                count++;
                Console.WriteLine("줄넘기를 {0}회 했습니다.", count);
            }
        }
    }
}


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)
        {
            string input = Console.ReadLine();
            char[] input_char = input.ToArray();
            int count = 0;

            Console.WriteLine();
            foreach(char c in input_char) //입력한 글자 수 만큼 반복
            {
                Console.Write(input);
                count++;
                Console.WriteLine(": {0}", count);
            }
        }
    }
}


 

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

[C#] 2021-08-20 오후 for문 연습 문제 11~17, challenge  (0) 2021.08.20
[C#] 2021-08-20 오후 for문 연습 문제 1~10  (0) 2021.08.20
2021-08-20 오전  (0) 2021.08.20
[C#] Random  (0) 2021.08.20
2021-08-19 연습문제  (0) 2021.08.19