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. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println("<<Машына с напиткоми>>");
  13.  
  14. int moneyAmount = 1000; //ваш кошелек
  15.  
  16. int cappucinoPrice = 140;
  17. int lattePrice = 120;
  18. int appleJuicePrice = 40;
  19. int milkPrice =50;
  20.  
  21. String drinks[] = {"капучино", "латте", "яблочный сок", "молоко"}; //вывод напитков на экран
  22. Integer prices[] = {140, 120, 40, 50}; //вывод цен
  23.  
  24. for(int i = 0; i < 4; i = i + 1) //вывод напитков + цен
  25. {
  26. System.out.println("Цена" + ":" + drinks[i] + " - " + prices[i]);
  27. }
  28.  
  29. boolean canBuyAnything = false;
  30.  
  31. if(moneyAmount >= cappucinoPrice) {
  32. System.out.println("Вы можете купить капучино");
  33. canBuyAnything = true;
  34. }
  35.  
  36. if(moneyAmount >= lattePrice) {
  37. System.out.println("Вы можете купить латте");
  38. canBuyAnything = true;
  39. }
  40.  
  41. if(moneyAmount >= appleJuicePrice) {
  42. System.out.println("Вы можете купить яблочьный сок");
  43. canBuyAnything = true;
  44. }
  45.  
  46. if(moneyAmount >= milkPrice) {
  47. System.out.println("Вы можете купить молоко");
  48. canBuyAnything = true;
  49. }
  50.  
  51. System.out.println("Пейте на здоровье!");
  52.  
  53. if(canBuyAnything == false) {
  54. System.out.println("Недостаточно средств! Учите джаву и идите работать!"); //выводится если нет средств не на один напиток
  55.  
  56. }
  57. }
  58. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
<<Машына с напиткоми>>
Цена:капучино - 140
Цена:латте - 120
Цена:яблочный сок - 40
Цена:молоко - 50
Вы можете купить капучино
Вы можете купить латте
Вы можете купить яблочьный сок
Вы можете купить молоко
Пейте на здоровье!