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. // your code goes here
  13. System.out.println("Кофе-машина");
  14. //Ввод суммы ====================================
  15. Scanner scanner = new Scanner(System.in);
  16. System.out.println("Внесите сумму");
  17. int moneyAmount = scanner.nextInt();
  18. scanner.close();
  19. //=====================================
  20. int espressoPrice = 80;
  21. int milkPrice = 50;
  22. int capuccinoPrice = 150;
  23. int waterPrice = 20;
  24. //=====================================
  25.  
  26. boolean canBuyAnything = false;
  27.  
  28. if(moneyAmount >= espressoPrice) {
  29. System.out.println("Вы можете купить еспрессо");
  30. canBuyAnything = true;
  31. }
  32. if(moneyAmount >= milkPrice) {
  33. System.out.println("Вы можете купить молоко");
  34. canBuyAnything = true;
  35. }
  36. if(moneyAmount >= capuccinoPrice) {
  37. System.out.println("Вы можете купить Капучино");
  38. canBuyAnything = true;
  39. }
  40. if(moneyAmount >= waterPrice) {
  41. System.out.println("Вы можете купить воду");
  42. canBuyAnything = true;
  43. }
  44. if(canBuyAnything == false) {
  45. System.out.println("Недостаточно средств. Учите Джаву идите работать");
  46. }
  47. }
  48. }
Runtime error #stdin #stdout #stderr 0.06s 2184192KB
stdin
Standard input is empty
stdout
Кофе-машина
Внесите сумму
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at Ideone.main(Main.java:17)