0
I have the following code: it is used to count how many seconds it takes to type a sentence. If I type BABA the result is 10. BUT I WISH THAT WHEN THERE WAS THE JOINING OF THE LETTER 'Q' + 'U,' (AS IN THE WORD CHEESE), HE WOULD CONSIDER A VALUE ONLY AND NOT THE VALUE OF 'Q' + THE VALUE OF 'U'.
I MEAN, 'Q' IN THIS CASE IS WORTH 7 AND U IS WORTH 6, I WANTED THE 'QU' JUNCTION TO BE WORTH ONLY 7, HOW IS IT? TYPE: HASHLETRAS.put("QU", 7);
package solucao;
import java.util.HashMap;
public class Contagem {
public static void main(String[] args) {
HashMap<String, Integer> hashLetras=new HashMap<String, Integer>();
hashLetras.put("A", 2);
hashLetras.put("B", 3);
hashLetras.put("C", 4);
hashLetras.put("D", 5);
hashLetras.put("E", 3);
hashLetras.put("F", 4);
hashLetras.put("G", 5);
hashLetras.put("H", 6);
hashLetras.put("I", 4);
hashLetras.put("J", 5);
hashLetras.put("K", 6);
hashLetras.put("L", 7);
hashLetras.put("M", 8);
hashLetras.put("N", 9);
hashLetras.put("O", 5);
hashLetras.put("P", 6);
hashLetras.put("Q", 7);
hashLetras.put("R", 8);
hashLetras.put("S", 9);
hashLetras.put("T", 10);
hashLetras.put("U", 6);
hashLetras.put("V", 7);
hashLetras.put("W", 8);
hashLetras.put("X", 9);
hashLetras.put("Y", 10);
hashLetras.put("Z", 11);
hashLetras.put(" ", 7); //ESPACO
String teste="QUEIJO";
int count=0;
for(int i=0; i<teste.length();i++){
String c = teste.charAt(i)+ "";
count = count+hashLetras.get(c);
}
System.out.println("O tempo foi de: "+count);
}
}
absolutely! Thank you
– Gabriella