/
Newcomer_25
/
array_var
Обзор
Документация
Войти
/
Newcomer_25
/
array_var
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
45 строк
2 KB
Newcomer_25
upload files
14 сен 2025, 16:22
14 сен 2025, 16:22
1de30fa
Код
Авторство
О чём код?
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] products = {"Молоко", "Хлеб", "Гречневая крупа"}; int[] prices = {50, 14, 80}; System.out.println("Список возможных товаров для покупки: "); for (int i = 0; i < products.length; i++) { System.out.println(i + 1 + ". " + products[i] + " " + prices[i] + " руб/шт"); } int sumProducts = 0; int[] count = new int[3]; while (true) { System.out.println("Выберите товар и количество или введите end: "); String input = scanner.nextLine(); if (input.equals("end")) { break; } String[] choice = input.split(" "); int productNumber = Integer.parseInt(choice[0]) - 1; int productQuantity = Integer.parseInt(choice[1]); count[productNumber] = productQuantity; for (int i = 0; i < 3; i++) { int currentPrice = prices[productNumber]; int totalPrice = currentPrice * count[i]; sumProducts += totalPrice; } } System.out.println("Ваша корзина: "); for (int i = 0; i < products.length; i++) { System.out.println(products[i] + " " + count[i] + " шт " + prices[i] + " руб/шт" + " " + count[i] * prices[i] + " руб в сумме"); } System.out.println("Итого:" + sumProducts + " руб"); } }