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

一毛錢
TA貢獻(xiàn)156條經(jīng)驗(yàn) 獲得超57個(gè)贊
出現(xiàn)這個(gè)的問(wèn)題是你的理解有問(wèn)題,Substring(開(kāi)始值,長(zhǎng)度)不是開(kāi)始值和結(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)注
- 1376 瀏覽
添加回答
舉報(bào)
0/150
提交
取消