日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第五章第四十九题(对元音和辅音进行计数)(Count vowels and consonants)

發布時間:2023/12/9 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第五章第四十九题(对元音和辅音进行计数)(Count vowels and consonants) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

*5.49(對元音和輔音進行計數)假設字母A、E、I、O、U為元音。編寫一個程序,提示用戶輸入一個字符串,然后顯示字符串中元音和輔音的數目。

Enter a string: Programming is fun
The number of vowels is 5
The number of consonants is 11

*5.49 (Count vowels and consonants)(Count vowels and consonants) Assume that the letters A, E, I, O, and U are vowels. Write a program that prompts the user to enter a string, and displays the number of vowels and consonants in the string.

Enter a string: Programming is fun
The number of vowels is 5
The number of consonants is 11

下面是參考答案代碼:

import java.util.*;public class CountVowelsAndConsonantsQuestion49 {public static void main(String[] args) {String userString;int vowelCount,consonantCount;vowelCount = consonantCount = 0;System.out.print("Enter a string: ");Scanner inputScanner = new Scanner(System.in);userString = inputScanner.nextLine();for(int strIndex = 0;strIndex < userString.length(); strIndex++){if("aeouiAEOUI".contains(""+userString.charAt(strIndex)))vowelCount++;else if(Character.isLetter(userString.charAt(strIndex)))consonantCount++;}System.out.printf("The number of vowels is %d\n", vowelCount);System.out.printf("The number of consonants is %d", consonantCount);inputScanner.close();} }

運行效果:

注:編寫程序要養成良好習慣
1.文件名要用英文,具體一點
2.注釋要英文
3.變量命名要具體,不要抽象(如:a,b,c等等),形式要駝峰化
4.整體書寫風格要統一(不要這里是駝峰,那里是下劃線,這里的邏輯段落空三行,那里相同的邏輯段落空5行等等)
5.普通變量,方法名要小駝峰,類名要大駝峰,常量要使用全部大寫加上下劃線命名法
6.要學習相應的代碼編輯器的一些常用快捷鍵,如:快速對齊等等

總結

以上是生活随笔為你收集整理的第五章第四十九题(对元音和辅音进行计数)(Count vowels and consonants)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。