The code should compare the 3rd character of the string with the number 3. But why is the condition wrong?
I’ve tried replacing ==
with .equals
, but the result is the same.
import java.lang.Character. *;
public class Main
{
public static void main (String args []) {
String s = "123456";
Character result1 = s.charAt (2);
Character condition = 3;
if (result1 == condition)
{
System.out.println (result1);
}
else {
System.out.println ("There was no comparison");
}
}
}
Answer 1, authority 100%
Thanks for the comment, everything works.
import java.lang.Character. *;
public class Main
{
public static void main (String args []) {
String s = "123456";
Character result1 = s.charAt (2);
Character condition = '3';
if (result1 == condition)
{
System.out.println (result1);
}
else {
System.out.println ("There was no comparison");
}
}
}