/
Shcod
/
java-hw-arrays
Обзор
Документация
Войти
/
Shcod
/
java-hw-arrays
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/Main.java
37 строк
1 KB
Shcod
first commit
28 июл 2026, 07:32
28 июл 2026, 07:32
c74c2b9
Код
Авторство
О чём код?
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] products = {"Хлеб", "Яблоки", "Молоко"}; int[] prices = {100, 200, 300}; int[] cart = new int[products.length]; int totalSum = 0; for (int i = 0; i < products.length; i++) { System.out.printf("%d. %s %d руб/шт\n", i + 1, products[i], prices[i]); } while (true) { System.out.println("Выберите товар и количество или введите `end`"); String input = scanner.nextLine(); if (input.equals("end")) { break; } String[] parts = input.split(" "); int productNumber = Integer.parseInt(parts[0]); int productCount = Integer.parseInt(parts[1]); cart[productNumber - 1] += productCount; totalSum += prices[productNumber - 1] * productCount; } System.out.println("Ваша корзина:"); for (int i = 0; i < cart.length; i++) { if (cart[i] != 0) { int sum = prices[i] * cart[i]; System.out.printf("%s %d шт %d руб/шт %d руб в сумме\n",products[i], cart[i],prices[i], sum); } } System.out.printf("Итого %d руб", totalSum); scanner.close(); } }