为了账号安全,请及时绑定邮箱和手机立即绑定

为什么定义的字符串最多只能输入3个字符,否则就会出错呢?

为什么定义的字符串最多只能输入3个字符,否则就会出错呢?

C#
三色堇忞 2016-04-13 22:41:59
//统计一串英文字符串的元音字母的个数using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _4_3{    class Program    {        static void Main(string[] args)        {            Console.WriteLine("输入一串字符串");            string s = Console.ReadLine();            string a="a";            string e="e";            string i="i";            string o="o";            string u="u";            int count=0;            for (int j = 0; j < s.Length -1; j++)            {                if (a.Equals(s.Substring(j, j + 1)) | e.Equals(s.Substring(j, j + 1)) | i.Equals(s.Substring(j, j + 1)) | o.Equals(s.Substring(j, j + 1)) | u.Equals(s.Substring (j,j+1)))                    count++;            }            Console.WriteLine("元音字母个数为:" + count);        }    }}
查看完整描述

1 回答

已采纳
?
一毛钱

TA贡献156条经验 获得超57个赞

出现这个的问题是你的理解有问题,Substring(开始值,长度)不是开始值和结束值,应该这样写

                if (a.Equals(s.Substring(j, 1)) | e.Equals(s.Substring(j, 1)) | i.Equals(s.Substring(j, 1)) | o.Equals(s.Substring(j, 1)) | u.Equals(s.Substring(j, 1)))
                    count++;


查看完整回答
1 反对 回复 2016-04-14
  • 1 回答
  • 0 关注
  • 1251 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信