FOR JAVA
I want to do something like this for JAVA but I haven't been able to create the algorithm exactly. Example h=2, e=3.5, l=43.9, o=32 When I type "hello" on the keyboard, the output will be "2, 3.5, 3.5, 43.9, 32". Can you help me?
I can only spell the letter I couldn't make the full word
CodePudding user response:
tl;dr
"hello"
.codePoints()
.mapToObj(
Map.of(
Character.codePointAt( "e" , 0 ) , new BigDecimal( "3.5" ) ,
Character.codePointAt( "h" , 0 ) , new BigDecimal( "2" ) ,
Character.codePointAt( "l" , 0 ) , new BigDecimal( "43.9" ) ,
Character.codePointAt( "o" , 0 ) , new BigDecimal( "32" )
) :: get
)
.toList()
Details
Define your collection of numbers assigned to each character which might be present in your inputs. For this we can use