我目前正在做一个练习(不是在别人给我之前做作业),我被困在了问题的最后一部分。
问题是:
Write a program which will input a String from the keyboard, output the number of
seperate words, where a word is one or more characters seperated by spaces. Your
program should only count words as groups of characters in the rang A..Z and a..z
我可以完成第一部分,您可以从我的代码中看到这一点:
进口java.util.Scanner;
public class Exercise10 {
public static void main(String[] args) {
String input;
int counter = 0;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter your text: ");
input = keyboard.nextLine();
for(int i = 0; i < input.length(); i++){
if(input.charAt(i) == ' '){
counter++;
}
}
System.out.println(counter + 1);
keyboard.close();
}
}
然而,让我困惑的是:
Your program should only count words as groups of characters in the rang A..Z and
a..z
在这种情况下我该怎么办?
https://stackoverflow.com/questions/19294793
复制相似问题