I am developing an application where I have to transpose from one music scale to another.
cdefgab as gabcdef
Following is the code:
String tune = "cdef gabc";
System.out.println(""+tune.replace("c","g")
.replace("d","a")
.replace("g","d"));
Current Output: daef dabd
Required output: gaef dabg
Try this instead
System.out.println(tune.replace("a", "\uFFFF")
.replace("d", "a")
.replace("g", "d")
.replace("c", "g")
.replace("f", "c")
.replace("b", "f")
.replace("e", "b")
.replace("\uFFFF", "e"));
note: \uFFFF is not a valid character by definition so it won't appear in a valid string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With