https://its.hvcc.edu/jojo/?p=297
进行此分配时,我需要打印方法的结果,但是我无法弄清楚如何调用它们。
public static int numWhitespace(String s) {
int count = 0,x;
for(x = 0; x<s.length();x++)
if(Character.isWhitespace(s.charAt(x)))
count++;
return count;
}
public static void main (String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("Enter a string for character classification: (EOF to end):");
while (kb.hasNext()){
String input = kb.nextLine();
System.out.println("inputLine = "+ input +"");
System.out.println("inputLine is "+ input.length() +" characters long and contains the following:");
System.out.println(); //Where i want all the other stuff
System.out.println("Enter a string for character classification: (EOF to end):");
}
}
答案 0 :(得分:1)
您可以像这样调用numWhitespace()
方法:
System.out.println("whitespaces = " + numWhitespace(input));
或先将其保存在变量中:
int whitespaces = numWhitespace(input);
System.out.println("whitespaces = " + whitespaces);