import java.util.Scanner; public class Ex1_1 { public static void main(String[] args) { @SuppressWarnings("all") Scanner sc = new Scanner(System.in); System.out.println("Введите числа для вычисления \nсреднего арифметического!!!"); int a = 0; int summ = 0; while (true){ System.out.print("число " + (a + 1) + ": "); int ch = sc.nextInt(a + 1); if (ch == 0000){ break; } ch = +ch; summ = summ + ch; ch++; } int i = summ / a; int j = summ % a; if (summ % a == 0) System.out.println("Ответ : " + i); else System.out.println("Ответ : " + i + " с остатком : " + j); } } This is the program code. When compiling, the following occurs: The compiler executes the loop once, and the second time it produces the following error:
Введите числа для вычисления среднего арифметического!!! число 1: 123123 Exception in thread "main" java.util.InputMismatchException: radix 1 less than Character.MIN_RADIX at java.util.Scanner.nextInt (Unknown Source) at Ex1_1.main (Ex1_1.java:13)
if I replace int ch = sc.nextInt (a + 1) with int ch = sc.nextInt () , then there will be an infinite loop
Enter the numbers to calculate the arithmetic average !!!
the number 1: 1
the number 1: 2
the number 1: 4
the number 1: 3
the number 1: 5
number 1: 7
number 1: 8
the number 1: 5
the number 1: 4
number 1: