【发布时间】:2019-03-26 08:38:32
【问题描述】:
我正在尝试制作一个将String 转换为Binary 的程序。为此,我将用户输入转换为 char 数组。使用for 循环逐一读取char 数组中的字符。
我的问题是如何从 char 数组中读取空格。这是我的代码。
for(int i = 0 ; i < UserInput.length() ; i++) {
char c = UserInput.charAt(i);
if (Character.isLetter(c)){
System.out.print ("letter");
}
else if (Character.isDigit(c)){
System.out.print ("number");
}
else if (c== " "){
System.out.print ("space");
}
else
{
System.out.println ("Special Char");
}
}
错误显示二元运算符 '=='else if ((c) == " ") 的操作数类型错误
【问题讨论】: