What is my error in a map in java?

Posted by amveg on Stack Overflow See other posts from Stack Overflow or by amveg
Published on 2010-05-08T18:01:02Z Indexed on 2010/05/08 18:08 UTC
Read the original article Hit count: 151

Filed under:
|
|
|

Hello everyone

I am trying to solve this problem: http://www.cstutoringcenter.com/problems/problems.php?id=4, but I cant figure out why my code doesnt solve this, I mean in the "for" how can I can multiply the letters? what is my error?, It just tell always 7, but I want to multiple all the letters, I hope you can help me

enter code here

public class ejercicio3 {

public static void main(String args[]) {

    Map<Character, Integer> telefono = new HashMap<Character, Integer>();

    telefono.put('A', 2);
    telefono.put('B', 2);
    telefono.put('C', 2);
    telefono.put('D', 3);
    telefono.put('E', 3);
    telefono.put('F', 3);
    telefono.put('G', 4);
    telefono.put('H', 4);
    telefono.put('I', 4);
    telefono.put('J', 5);
    telefono.put('K', 5);
    telefono.put('L', 5);
    telefono.put('M', 6);
    telefono.put('N', 6);
    telefono.put('O', 6);
    telefono.put('P', 7);
    telefono.put('R', 7);
    telefono.put('S', 7);
    telefono.put('T', 8);
    telefono.put('U', 8);
    telefono.put('V', 8);
    telefono.put('W', 9);
    telefono.put('X', 9);
    telefono.put('Y', 9);


    String mensaje = "Practice";
    int producto = 1;

    for (char c : mensaje.toCharArray()) {

        if (telefono.containsKey(c)) {
            producto = telefono.get(c) * producto;
            System.out.println(producto);
        }
    }
}

}

© Stack Overflow or respective owner

Related posts about java

Related posts about map