/
advo_kitty
/
27.11.2025_Task7
Обзор
Документация
Войти
/
advo_kitty
/
27.11.2025_Task7
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
46 строк
2 KB
advo_kitty
upload files
27 ноя 2025, 20:07
27 ноя 2025, 20:07
438170f
Код
Авторство
О чём код?
import java.util.*; public class Main { public static void main(String[] args) { String[] products = {"Яблоки", "Бананы", "Хлеб", "Молоко", "Яйца", "Сыр", "Курица"}; double[] prices = {120.50, 80.00, 45.30, 75.00, 60.20, 250.00, 320.70}; int[] basket = new int[products.length]; Scanner scanner = new Scanner(System.in); System.out.println("Доступные продукты:"); for (int i = 0; i < products.length; i++) { System.out.printf("%d: %s — %.2f руб.\n", i, products[i], prices[i]); } System.out.println("Введите номер и количество продукта или 'end' для завершения:"); while (true) { String input = scanner.nextLine(); if (input.equalsIgnoreCase("end")) { break; } String[] parts = input.split("\\s+"); int index = Integer.parseInt(parts[0]); int quantity = Integer.parseInt(parts[1]); basket[index] += quantity; System.out.printf("Добавлено: %d × %s\n", quantity, products[index]); } System.out.println("\nВаша корзина:"); double total = 0.0; boolean isEmpty = true; for (int i = 0; i < basket.length; i++) { if (basket[i] > 0) { double itemTotal = basket[i] * prices[i]; total += itemTotal; System.out.printf("%s — %d шт. × %.2f = %.2f руб.\n", products[i], basket[i], prices[i], itemTotal); isEmpty = false; } } System.out.printf("\nОбщая сумма: %.2f руб.\n", total); } }