我目前的代码如下,我需要使用outputWithoutWhitespace()
方法打印用户的输入,但我很难理解应用它的位置/如何实际使用它。我相信我应该使用\t
。使用outputWithoutWhitespace()
方法打印时如何删除空格?
import java.util.Scanner;
public class TextAnalyzer {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String userInput = " ";
int getNumOfCharacters = 0;
int count = 0;
System.out.println("Enter a sentence or phrase: ");
userInput = scnr.nextLine();
System.out.println("You entered: " + userInput);
count = getNumOfCharacters(userInput);
System.out.print("Number of characters: "+ count);
}
public static int getNumOfCharacters(String userInput) {
int userCount = userInput.length();
return userCount;
}
}
答案 0 :(得分:0)
gt