fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9. public static void main(String[] args) throws java.lang.Exception {
  10. Map<Integer, Integer> hMap = new HashMap<>();
  11.  
  12. // initializing running variables here to reuse in "display hashmap" loop
  13. int key = 48;
  14. int values = 65;
  15.  
  16. // set keys and values to hashmap via nested for-loop
  17. for (key = 48; key < 74 && values < 91; key++) {
  18. hMap.put(key, values);
  19. values++;
  20. }
  21.  
  22. // display hashmap via nested for-loop
  23. for (key = 48; key < 74; key++) {
  24. System.out.println("Key: " + key + ", Value: " + hMap.get(key));
  25. }
  26. }
  27. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
Key: 48, Value: 65
Key: 49, Value: 66
Key: 50, Value: 67
Key: 51, Value: 68
Key: 52, Value: 69
Key: 53, Value: 70
Key: 54, Value: 71
Key: 55, Value: 72
Key: 56, Value: 73
Key: 57, Value: 74
Key: 58, Value: 75
Key: 59, Value: 76
Key: 60, Value: 77
Key: 61, Value: 78
Key: 62, Value: 79
Key: 63, Value: 80
Key: 64, Value: 81
Key: 65, Value: 82
Key: 66, Value: 83
Key: 67, Value: 84
Key: 68, Value: 85
Key: 69, Value: 86
Key: 70, Value: 87
Key: 71, Value: 88
Key: 72, Value: 89
Key: 73, Value: 90