/
weazweazweaz
/
ArraysHW
Обзор
Документация
Войти
/
weazweazweaz
/
ArraysHW
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
42 строки
1 KB
weazweazweaz
upload files
14 ноя 2025, 00:00
14 ноя 2025, 00:00
e5eb4f7
Код
Авторство
О чём код?
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] products = {"Молоко", "Хлеб", "Гречневая крупа"}; int[] prices = {50, 14, 80}; int[] cart = new int[products.length]; for (int i = 0; i < products.length; i++) { System.out.printf("%s %d руб/шт\n", products[i], prices[i]); } while (true) { System.out.println("Выберите товар и количество или введите end"); String stringInput = sc.nextLine(); if (stringInput.equalsIgnoreCase("end")) { break; } String[] stringParts = stringInput.split(" "); int numberProduct = Integer.parseInt(stringParts[0]) - 1; int productCount = Integer.parseInt(stringParts[1]); cart[numberProduct] += productCount; } System.out.println("Ваша корзина: "); int resultPrice = 0; for (int i = 0; i < products.length; i++) { int productPrice = cart[i] * prices[i]; System.out.printf("%s %d руб/шт %d в сумма\n", products[i], prices[i], productPrice); resultPrice += productPrice; } System.out.printf("Итого: %d", resultPrice); } }