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);
More Related Contents:
- How do I put a method as a parameter in a method call? [duplicate]
- Using a custom truststore in java as well as the default one
- Display current time in 12 hour format with AM/PM
- keytool error Keystore was tampered with, or password was incorrect
- How to get a string between two characters?
- List versus ArrayList as reference type?
- Spring Boot Jackson date and timestamp Format
- How to get unique random product in node Firebase?
- Android Firestore convert array of document references to List
- How do determine if an object is locked (synchronized) so not to block in Java?
- Eclipse reading stdin (System.in) from a file
- Minimum Spring version compatible with Java 11
- Create simple POJO classes (bytecode) at runtime (dynamically)
- Why an abstract class implementing an interface can miss the declaration/implementation of one of the interface’s methods?
- indexOf Case Sensitive?
- java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
- Split a String at every 3rd comma in Java
- Most efficient way to see if an ArrayList contains an object in Java
- Migrating from log4j to log4j2 – properties file configuration
- Image Orientation – Android
- What is a simple, effective way to debug custom Kafka connectors?
- Change JButton gradient color, but only for one button, not all
- How to use Collections.sort() in Java?
- javax.validation.ValidationException: HV000183: Unable to load ‘javax.el.ExpressionFactory’
- Android app in Eclipse: Edit text not showing on Graphical layout
- how to add a picture to a .docx document with Apache POI XWPF in java
- Core dump taken with gcore, jmap conversion to hprof file format fails with Error message
- Running a bash shell script in java
- Android schema validation
- Difference between the maven-assembly-plugin, maven-jar-plugin and maven-shade-plugin?