+ 1

I need help! PLEASE!!!!!

Is it possible to convert this code with "HashMap"? import java.util.*; import java.lang.*; import java.io.*; { public static void main (String[] args) throws java.lang.Exception { int moneyAmount = 100; String drinks[] = {"латте", "капучино", "воду"}; Integer prices[] = {140, 200, 35}; for(Integer i = 0; i < drinks.length; i = i + 1) { if(moneyAmount >= prices[i]) { System.out.println("Вы можете купить " + drinks[i]); } } } }

5th Oct 2018, 9:19 AM
Александр_
Александр_ - avatar
1 ответ
+ 1
Sure.. Read here https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html and see how use methods .put, .get, .keySet (with latter you probably want use an iterator)
5th Oct 2018, 10:22 AM
KrOW
KrOW - avatar