C#
배열에서 찾으려는 숫자의 개수 구하기
s0002
2023. 1. 9. 11:46
using System;
using System.Collections.Generic;
using System.Text;
namespace Study07
{
class App
{
//생성자
public App()
{
Console.WriteLine("App생성자");
int[] array = { 1, 3, 1, 3, 2, 3, 1, 4, 4, 5 };
Console.WriteLine("개수가 궁금한 숫자 입력");
int num = Convert.ToInt32(Console.ReadLine());
int count=0;
for (int i = 0; i < array.Length; i++)
{
if (array[i] == num)
{
count++;
}
}
if (count == 0)
Console.WriteLine("{0}은 배열에 존재하지 않습니다", num);
else
Console.WriteLine("{0}의 갯수:{1}", num, count);
}
}
}