Home java Exception in Thread "Main" java.util.inputmismatchexception

Exception in Thread “Main” java.util.inputmismatchexception




This is the program code.
When compiling, the following happens: the compiler performs the cycle once, and the second time it gives out such an error:

enter numbers to calculate
Middle arithmetic !!!
Number 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) on int ch = sc.nextint () , then there will be an infinite cycle

Enter the numbers to calculate
Middle arithmetic !!!

number 1: 1

number 1: 2

number 1: 4

number 1: 3

number 1: 5

number 1: 7

number 1: 8

number 1: 5

number 1: 4

Number 1:

Answer 1, Authority 100%

As for me, here is the wrong use of the Nextint () method

sc.nextint () – Method for obtaining an intention of a set of a character obtained from the presented flow

SC.NEXTINT (INT RADIX) – Method for obtaining a smart view of a set of a symbol obtained from the presented stream in the SS based on the NexTint (int Radix) method parameter

To solve the problem simply replaced int CH = SC.NEXTINT (A + 1) on int CH = SC.NEXTINT ()

Yes, and the cycle did not finish the first iteration, since after the first call nextint () throws the exception of inputmismatchexception and the method is forced to interrupt and throw an exception.

Answer 2, Authority 14%

Public Static Void Main (String [] Args) {
  Scanner SC = NEW Scanner (System.in);
  System.out.PrintLN ("Enter the numbers to calculate \ Nixed arithmetic !!!");
  int a = 0;
  INT SUMM = 0;
  While (True) {
    System.Out.print ("Number" + (A + 1) + ":");
    int ch = sc.nextint ();
    if (ch == 0) {
    Summ + = CH;
    a ++;
  int i = Summ / A;
  int j = Summ% A;
  if (Summ% a == 0)
    System.Out.printLN ("Answer:" + I);
    System.out.PrintLN ("Answer:" + i + "with the residue:" + j);
  SC.Close ();

So everything works. The error was in SC.NEXTINT (A + 1) and in the logic of the program

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions