我目前有以下Java代码。
public class lesson8
{
static Console c; // The output console
public static void main (String[] args)
{
c = new Console ();
String user;
int length, counter, spacecounter;
spacecounter=0;
c.print("Enter a string. ");
user = c.readLine();
length = (user.length()-1);
for (counter=0;counter<length;counter++)
{
if (user.charAt(counter) = "")
{
spacecounter++;
}
}
c.println("There are "+spacecounter+" spaces in your string.");
c.println("There are "+counter+" characters in your string.");
// Place your program here. 'c' is the output console
// main method
}
}
我在这部分收到一个错误:
if (user.charAt(counter) = "")
错误是
赋值的左边必须是一个变量。
我将其更改为“==”,但现在我收到另一个错误:
左子表达式“char”的类型与右子表达式“java.lang.String”的类型不兼容。
我将如何解决这个问题?
谢谢!