Затем вы можете создать карту:
//Initial color
String color = "#bf6116";
//Create a map which hold percent and its corresponding String
Map<Integer, String> mapPercent = Map.of(100, "FF", 95, "F2", 10, "1A");
//user input, to explain I use a static variable
int userInput = 10;
if(mapPercent.containsKey(userInput)) {
//Use replaceFirst or subscring to put the corresponding String
color = color.replaceFirst(
"#(.*)", //the regex match # as group 1 and the rest as group 2
//put the corresponding string between the two groups
String.format("$0%s$1", mapPercent.get(userInput))
);
}
System.out.println(color);//result in this case is #1Abf6116
Примечание: Map.of
из Java 10, вы можете использовать обычную карту и поместить входные данные