WHAT IS THE SUM OF THE PRINTED NUMBERS IN THE CODE BELOW? IF THE IS A COMPILING ERROR, TYPE 0. This is code in Java 7. Also assume that we already imported the Java classes HashMap and Map and there is no class statement...
public static void main(String[] args)
{
final Map<Character, Integer> map;
final String str = "hello world";
map = new HashMap<>();
map.put('a', 1);
map.put('b', 2);
map.put('c', 3);
map.put('d', 4);
map.put('e', 5);
map.put('f', 6);
map.put('g', 7);
map.put('h', 8);
map.put('i', 9);
map.put('j', 10);
map.put('k', 11);
map.put('l', 12);
map.put('m', 13);
map.put('n', 14);
map.put('o', 15);
map.put('p', 16);
map.put('q', 17);
map.put('r', 18);
map.put('s', 19);
map.put('t', 20);
map.put('u', 21);
map.put('v', 22);
map.put('w', 23);
map.put('x', 24);
map.put('y', 25);
map.put('z', 26);
for(final char c : str.toCharArray())
{
final Integer val;
val = map.get(c);
if(val == null)
{
}
else
{
System.out.print(val + " ");
}
}
System.out.println();
}
}
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Well according to the table given, each letter has a corresponding value so the letter so, "Hello World"=8 5 12 12 15 23 15 18 12 4 (each letter of the string) is equal to 124