public class Test{ public static void main(String[] args){ String s1 = "runoob"; String s2 = "runoob"; System.out.println("s1 == s2 is:" + s1 == s2);}}
时间: 2024-02-12 09:26:22 浏览: 142
The code you provided has a small mistake in the print statement. The expression `"s1 == s2 is:" + s1` is concatenated with `== s2` before being passed to `System.out.println()`. This causes a compilation error because you cannot concatenate a string with a boolean value directly.
To fix this, you need to use parentheses to group the concatenation expression properly. Here's the corrected code:
```java
public class Test {
public static void main(String[] args) {
String s1 = "runoob";
String s2 = "runoob";
System.out.println("s1 == s2 is: " + (s1 == s2));
}
}
```
In this corrected code, the expression `(s1 == s2)` is properly grouped and then concatenated with the string `"s1 == s2 is: "`.
阅读全文