简体   繁体   English

错误:意外类型,必需:变量并找到:值

[英]Error: unexpected type, required: variable and found: value

I am trying to read in a string using a for loop but its giving me an error.我正在尝试使用 for 循环读取字符串,但它给了我一个错误。 Just checking if current character is "a":只需检查当前字符是否为“a”:

在此处输入图像描述

You must use == instead of = .您必须使用==而不是=

In Java, we can compare two characters either by using the equals == operator or the equals() method of the Character class.在 Java 中,我们可以使用 equals ==运算符或Character类的equals()方法来比较两个字符。

In your case:在你的情况下:

if (inputString.charAt(i) == 'a') {
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM