Java Incomparable Data types char and String

前端 未结 3 1791
忘掉有多难
忘掉有多难 2021-01-18 17:21

When I run the Javac, it tells me that i have an incomparable data types char and String in the

while(responseChar == \"y\")

not sure what

3条回答
  •  没有蜡笔的小新
    2021-01-18 18:17

    Optionally you could use the big C Character class to convert your char to a String:

    String converted = Character.toString(responseChar); 
    while(converted.equalsIgnoreCase("y"))
    {
      // ...
    }
    

    But this version is much more verbose than the literal comparison suggested by Jeffrey

提交回复
热议问题