/
times
/
netologydz
Обзор
Документация
Войти
/
times
/
netologydz
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
41 строка
2 KB
times
upload files
20 фев 2026, 00:06
Верифицирован
20 фев 2026, 00:06
e9a7522
Код
Авторство
О чём код?
import java.util.Scanner; public class Main { public static void main(String[] args) { String[] products = {"Хлеб", "Яблоки", "Молоко"}; int[] prices = {100, 200, 300}; for (int i = 0; i < products.length; i++) { System.out.println(i + 1 + ") " + products[i] + " " + prices[i] + " руб/шт"); } int[] counts = new int[products.length]; Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Выберите товар и количество или введите end"); String line = scanner.nextLine(); if (line.equals("end")) { break; } else { String[] parts = line.split(" "); int productNumber = Integer.parseInt(parts[0]); int amount = Integer.parseInt(parts[1]); int index = productNumber - 1; counts[index] += amount; } } System.out.println("Ваша корзина:"); int total = 0; for (int i = 0; i < products.length; i++) { if (counts[i] > 0) { int lineSum = counts[i] * prices[i]; total += lineSum; System.out.println( products[i] + " " + counts[i] + " шт " + prices[i] + " руб/шт " + lineSum + " руб в сумме "); } } System.out.println("Итого " + total + " руб"); } }