How do I covert this ternary statement to an if else statement? (Java) [closed]

There are many ways, it depends on your logic, here is one of the solution you can do:

int index;
if (i + 1 == necklace.length()) {
    index = 0;
} else {
    index = i + 1;
}
char rightColor = necklace.charAt(index);

Leave a Comment