java - set number to char of string and sum that number -


for example :
have edittext string , want convert every char of string constant number , sum number of characters , save on int variable.

define custom hashmap char key , int value :

hashmap<character,integer> charactermap = new hashmap<character, integer>(); charactermap.put('a',10); charactermap.put('p',20); charactermap.put('l',8); charactermap.put('e',4); 

sum of each character value :

string data = "apple"; char[] chararray = data.tochararray(); int total=0; for(char ch : chararray){    total+=charactermap.get(ch); } system.out.print("total : "+total); 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -