/
kanisavi
/
Course_arrays
Обзор
Документация
Войти
/
kanisavi
/
Course_arrays
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
46 строк
2 KB
Карина Басова
create Main.java
05 дек 2025, 14:57
05 дек 2025, 14:57
827f52c
Код
Авторство
О чём код?
{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] products = {"Молоко", "Хлеб", "Гречневая крупа", "Яйца"}; int[] prices = {90, 50, 100, 80}; int[] myProducts = {0, 0, 0, 0}; menu(products, prices); int productNumber; int productCount; int totalCost = 0; while (true) { String input = scanner.nextLine(); if ("end".equals(input)) { System.out.println("Ваша корзина: "); for (int i = 0; i < products.length; i++){ if (myProducts[i] != 0) { System.out.printf("%s %d шт %d руб/шт %d руб в сумме\n", products[i], myProducts[i], prices[i], myProducts[i] * prices[i]); } totalCost += myProducts[i] * prices[i]; } System.out.printf("Итого %d руб", totalCost); break; } else { String[] parts = input.split(" "); productNumber = Integer.parseInt(parts[0]) - 1; productCount = Integer.parseInt(parts[1]); myProducts[productNumber] += productCount; } } } public static void menu(String[] products, int[] prices) { System.out.println("Список возможных товаров для покупки: "); for (int i = 0; i < products.length; i++) { System.out.println(i + 1 + "." + products[i] + " " + prices[i] + "руб/шт"); } System.out.println("Выберите товар и количество или введите end"); } }