從鍵盤輸入字串,按字母 數字和其它字元分類統計個數

2022-12-13 19:11:23 字數 586 閱讀 7387

1樓:宋愛景介環

system.out.println("請輸入字串:");

scanners=

newscanner(system.in);

string

string

=s.nextline();

system.out.println(string);

intx=0,y=0,c=0,b=0,sum=string.length();

for(int

i=0;i<=sum-1;i++)

else

if(string.codepointat(i)>=65&&string.codepointat(i)<=90||string.

codepointat(i)>=97&&string.codepointat(i)<=122)

else

if(string.codepointat(i)==32)else

}system.out.println("總共有"+sum+"個字元!

"+"數字有"+x+"個,"+"字母有"+y+"個,"+"空格有"+c+"個,"+"其他字元有"+b+"個。");

C語言 用字元陣列從鍵盤輸入字串,刪除字串中所有

1 遍歷字串 2 對每個字元 判斷,如果不是字母,則刪除。刪除可以通過後續字元前專移,覆蓋要刪 屬除字元的方式實現。如下 int main s j 0 printf s n s include include include int main str2 j 0 printf s str2 getch...

從鍵盤輸入字串 將其中的小寫字母全部轉換成大寫字母 C語言

include main char a 100 char p a scanf s a while p 0 if p a p z p p 32 printf c p p c語言程式設計,從鍵盤輸入一字串,將其中的小寫字母全部轉換成大寫字母 小寫字母全部轉換成大寫字母的源 如下 includevoid ...

編寫函式,從鍵盤輸入字串,分別統計其中的大寫字母,小寫字母以及數字的個數

看你用什麼程式語言.vb的把字元轉換成ascii碼會變成數字,哪些數字是小寫哪些是大寫就可以分開了 詳細一點的我忘了 include include using namespace std int main cout the number of digit is num endl cout the ...