C#/수업내용
[C# 7일차] 배열과 input
왹져박사
2023. 1. 9. 11:30
input: (1~5까지)
input:2이면
배열에 2가 몇 개 있는지 출력
App Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study07
{
class App
{
//생성자
public App()
{
Console.WriteLine("App 생성자");
Console.WriteLine();
int[] numbers = { 1, 3, 1, 3, 2, 3, 1, 4, 4, 5 };
int input;
Console.Write("숫자를 입력하세요(1~5): ");
input = Convert.ToInt32( Console.ReadLine());
int count = 0;
for(int i = 0; i < numbers.Length; i++)
{
if(input == numbers[i])
{
count++;
}
}
Console.WriteLine(count);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study07
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
실행 결과