C# 上机题 写一个静态方法,输出字符串中大小写字母、数字和其他字符个数
2016-04-01 16:46
656 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 {//2.输入一个由若干字符组成的字符串,输出其中的大写字母、小写字母、数字和其他字符的个数。 class Program { static void Main(string[] args) { Console.Write("请输入一串数字: "); string s = Console.ReadLine(); char[] chnum = s.ToCharArray(); int count = 0, Count = 0, other = 0 ,figure=0; for ( int i = 0; i < s.Length; i ++) { if ( (char)s[i]>'a'&&(char)s[i]<'z') { Count++; } if ((char)s[i] > 'A' && (char)s[i] < 'Z') { count++; } if ((int)s[i] > '0' && (int)s[i] < '9') { figure++; } else { other++; } } Console.WriteLine("Count={0} ,count={1} ,fihure={2} ,other={3}",Count ,count ,figure ,other); Console.ReadKey(); } } }
运行结果:
学习总结: 之前用C++语言写过这类题,所以换汤不换药,只是用另一种语言又写了一遍,熟练使用C#语言。
相关文章推荐
- c#-输出参数
- C#学习(9):通过反射设置泛型类型的属性及值
- C#大文件读取和查询--内存映射
- C#中axWindowsMediaPlayer控件的用法
- C#中,switch case语句中多个值匹配一个代码块的写法
- C# 清空sessin
- C# Dictionary用法总结
- C# ——输入 若干字符组成的字符串,写静态方法,统计并输出各种字符的数目
- C#装箱与拆箱
- c# 最简单的线程
- C#基本语法学习(十)
- C# this 关键字
- c#中委托与多线程的实质
- 2016-4-1--C#泛型
- 【转】C# 开发Chrome内核浏览器(WebKit.net)
- [C#]自定义消息收发
- C#小知识点
- C#中类型分析中的常见问题 Type
- C# --数组
- C# 特性详解