Java 如何调用方法来打印?

Java 如何调用方法来打印?,java,methods,invoke,Java,Methods,Invoke,执行此任务时,我需要打印方法的结果,但我不知道如何调用它们 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[]

执行此任务时,我需要打印方法的结果,但我不知道如何调用它们

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):");
    }
}
public static int numWhitespace(字符串s){
整数计数=0,x;

对于(x=0;x您可以像这样调用
numWhitespace()
方法:

System.out.println("whitespaces = " + numWhitespace(input));
或者先将其保存在变量中:

int whitespaces = numWhitespace(input);
System.out.println("whitespaces = " + whitespaces);