package chapter06;import java.util.Scanner;publicclassCode_20{
publicstaticvoidmain(String[] args){
Scanner input =newScanner(System.in);
System.out.print("Enter a string: ");
String str = input.nextLine();
System.out.println("The number of the string is "+countLetters(str));}publicstaticintcountLetters(String s){
int count =0;for(int i =0;i < s.length();i++){
if(Character.isLetter(s.charAt(i)))
count++;}return count;}}
結果は次のことを示しています。
Enter a string: jxh1025?
The number of the string is 3
Process finished with exit code 0