import java.util.InputMismatchException; import java.util.Scanner; public class Main { public static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { System.out.println("ÐÑивеÑ, на ÑколÑÐºÐ¸Ñ Ñеловек Ð½ÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ð¾ ÑазделиÑÑ ÑÑÑÑ?"); int peopleCount = getCountOfPeople(); ProductCalculator productCalculator = new ProductCalculator(peopleCount); productCalculator.inputProducts(); } public static int getCountOfPeople() { int peopleCount = 0; while (true) { try { peopleCount = scanner.nextInt(); if (isCorrectPeopleCount(peopleCount)) { break; } } catch (InputMismatchException er) { System.out.println("ÐекоÑекÑное знаÑение, попÑобÑйÑе дÑÑгое"); scanner.nextLine(); } } return peopleCount; } public static boolean isCorrectPeopleCount(int peopleCount) { if (peopleCount <= 0) { System.out.println("ÐолиÑеÑÑво Ñеловек менÑÑе 1. ÐÑо некоÑÑекÑное знаÑение Ð´Ð»Ñ Ð¿Ð¾Ð´ÑÑÑÑа. ÐведиÑе новое знаÑение."); return false; } else if (peopleCount == 1) { System.out.println("ÐолиÑеÑÑво Ñеловек, введÑннÑÑ Ð¿Ð¾Ð»ÑзоваÑелем Ñавно 1. Ð ÑÑом ÑлÑÑае Ð½ÐµÑ ÑмÑÑла ниÑего ÑÑиÑаÑÑ Ð¸ делиÑÑ. ÐведиÑе новое знаÑение."); return false; } else { return true; } } }