Hey I have a LinkedHashMap containing several values but I'm struggling to print it in the format I want. It will be passed a size integer, and I want it to print out the values in a square format, and if there's not a value for a certain key up to the size value to place a 0 there instead.
Say these are the values in the hashmap, first is location, 2nd is value
hashmap.put(1, 10);
hashmap.put(2, 90);
hashmap.put(4, 9);
hashmap.put(7, 2);
hashmap.put(11, 4);
hashmap.put(14, 45);
I'd like it to print as follows after being passed the value 4 (the height/width).
0 10 90 0
9 0 0 2
0 0 0 4
0 0 45 0
Sorry this is really badly described, not sure how to say it any better! Cheers for any help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…