Как вызвать метод для печати? - PullRequest
0 голосов
/ 03 апреля 2019

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):");
    }
}

1 Ответ

1 голос
/ 03 апреля 2019

Вы можете вызвать метод numWhitespace() следующим образом:

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

или сначала сохраните его в переменной:

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