正在加载图片...
Example: Counting Vowels char letter string name inputBox getstring ("What is your name? nt numberofCharacters name. lengthoi int yowelCount for (int 1=0; i< numberofCharacters; i++)( Here' s the code to count the number of letter name charAt(i) vowels in the input string if letter a letter letter = 'elI letter EI letter =s 'i II letter letter == 'o lett letter = uIl letter U vowelCount++ messageBox. show(name " your name has " t vowelCount vowels" C 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8-10© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 8 - 10 Example: Counting Vowels char letter; String name = inputBox.getString("What is your name?"); int numberOfCharacters = name.length(); int vowelCount = 0; for (int i = 0; i < numberOfCharacters; i++) { letter = name.charAt(i); if ( letter == 'a' || letter == 'A' || letter == 'e' || letter == 'E' || letter == 'i' || letter == 'I' || letter == 'o' || letter == 'O' || letter == 'u' || letter == 'U' ) { vowelCount++; } } messageBox.show(name + ", your name has " + vowelCount + " vowels"); Here’s the code to count the number of vowels in the input string
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有