//統(tǒng)計一串英文字符串的元音字母的個數(shù)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("元音字母個數(shù)為:" + count);? ? ? ? }? ? }}
1 回答
已采納

一毛錢
TA貢獻156條經(jīng)驗 獲得超57個贊
出現(xiàn)這個的問題是你的理解有問題,Substring(開始值,長度)不是開始值和結(jié)束值,應(yīng)該這樣寫
????????????????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 回答
- 0 關(guān)注
- 1353 瀏覽
添加回答
舉報
0/150
提交
取消