fork(3) 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. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println("Кофе-машина");
  13.  
  14. int moneyAmount = 170;
  15. Map<Integer, String> drinkDictionary = new TreeMap<>();
  16. drinkDictionary.put(120, "капучино");
  17. drinkDictionary.put(160, "латте");
  18. drinkDictionary.put(20, "воду");
  19. drinkDictionary.put(15, "молоко");
  20. boolean canBuyAnything = false;
  21. for(Map.Entry<Integer, String> item : drinkDictionary.entrySet()){
  22. if (moneyAmount >= item.getKey()) {
  23. System.out.println("Вы можете купить " + item.getValue());
  24. canBuyAnything = true;
  25. }
  26. }
  27. if (!canBuyAnything) {
  28. System.out.println("Недостаточно средств");
  29. }
  30. }
  31. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
Кофе-машина
Вы можете купить молоко
Вы можете купить воду
Вы можете купить капучино
Вы можете купить латте