Java Incomparable Data types char and String

前端 未结 3 1765
忘掉有多难
忘掉有多难 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

    0 讨论(0)
  • To define a character literal, use a single quote: '. Double quotes define string literals.

    while(responseChar == 'y')
    
    0 讨论(0)
  • 2021-01-18 18:21

    Instead of "y" do this 'y'. "" Represents string.

    0 讨论(0)
提交回复
热议问题