<문제>
문자열을 입력받아 아스키코드를 이용해
대문자, 소문자, 숫자, 특수문자를 구분하라
<입력>
ASnvsdk45/*
<출력>
대문자: 2
소문자: 5
숫자: 2
특수문자: 2
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp17
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("문자열을 입력해주세요:");
char[] a ;
int c1=0, c2=0, c3=0,c4=0;
a = Console.ReadLine().ToCharArray();
for (int i = 0; i < a.Length; i++) {
if ((int)a[i] >= 65 && (int)a[i] <= 90)
{
c1++;
}
else if ((int)a[i] >= 97 && (int)a[i] <= 122)
{
c2++;
}
else if ((int)a[i] >= 48 && (int)a[i] <= 57)
{
c3++;
}
else { c4++; }
}
Console.WriteLine($"대문자:{c1}");
Console.WriteLine($"소문자:{c2}");
Console.WriteLine($"숫자:{c3}");
Console.WriteLine($"특수문자:{c4}");
}
}
}
'코딩연습 > C#' 카테고리의 다른 글
[c#] c# 윈폼과 오라클(DB)연동하여 미니 주소록만들기 (2) | 2020.06.18 |
---|---|
[C#]윈폼(Windows Form)에 마우스 이벤트로 폼 배경 변경(랜덤) (1) | 2020.06.16 |
[C#]람다식을 이용하여 계산기 클래스 만들기 (0) | 2020.06.15 |
[C#]식트리 (0) | 2020.06.15 |
[C#]람다식(Action대리자 (0) | 2020.06.15 |