Questions tagged [inputmismatchexception]

Use this tag on questions regarding input mismatch exceptions that occur when using the `Scanner` object.

The InputMismathException is a Java I/O exception that is thrown when the Scanner object encounters an input which it does not expect. An example would be expecting a double, but receiving a String token instead. This is a runtime exeception that inherits from NoSuchElementException.

258 questions
1
vote
2 answers

basic Java While(true) question relating to exception handling

I have researched while(true) loops for past hour but I was unable to find my answers about this loop. public class Test { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { …
1
vote
1 answer

How do i overgo a misMatchExeption in an armstrongnumber calculation in Scanner?

I have written the following code, with following conditions. I was not allowed to use any String or Math class, so I used for loops, to break the number down. It works for e.g 153 and 54883 but for numbers like 4679307774 the Scanner Type gives me…
1
vote
1 answer

java.util.InputMismatchException when using Scanner and .nextInt()

I am just trying to make a simple program to have some fun but i got this code here: import java.util.Scanner; import static java.lang.System.in; import static java.lang.System.out; public class test5 { public static void main(String[] args) { …
RawGamingYT
  • 41
  • 1
  • 5
1
vote
0 answers

Issues Handling InputMismatchExceptions

Can anyone please tell me why I keep getting InputMismatchExceptions? I have been stuck trying to understand whats happening and just can't seem to figure it out. The program is suppose to read a input file of high temperatures and then create a…
DrtyG
  • 5
  • 3
1
vote
1 answer

Java Scanner Throws InputMismatchException even when next token appears to fit data type

I'm currently working with the Java Scanner class and I'm getting a very strange InputMismatchException. I initialize the scanner like this: Scanner in = new Scanner(new File(fileName)); in.useDelimiter("\n?.*:"); When I call…
1
vote
2 answers

Getting InputMismatchException when reading an int from a file with Scanner

I am working on a program which imports a library from a generated file. The file generates properly and is found by Scanner. The first line has a single int as written by pw.println(cdarchive.getNumber()); Elsewhere in the code. This part…
1
vote
2 answers

Basic addition of two numbers

Sorry for asking an easy question, but I'm a total beginner here. So the problem is when I copy the following code into my eclipse, it's working fine. But when I change the type of the variables from int to double it's showing some kind of an error.…
Aba74
  • 55
  • 4
1
vote
1 answer

Java Input Mismatch Exception with a specialized txt file

I am working on a program and I need to scan in a txt file. The txt file is guaranteed to follow a particular format in terms up where and when different types occur. I try to take advantage of this in my program and use a scanner to put the parts I…
Ryan Miller
  • 113
  • 2
1
vote
2 answers

InputMismatchException with Scanner when reading double from string with \n—Java

I am trying to read from a CSV file using the Scanner but I am getting an InputMismatchException when I try and read the last double and are there is more than one line in my CSV file. I think this is because it is reading \n as part of the double.…
1
vote
1 answer

Input mismatch when reading double from file

I have to write a program that will read the names and balances from text file "balances.txt" and organize into a report that will then sum up the balances into a total. This is what the file contains: JAKIE JOHNSON,2051.59 SAMUEL PAUL…
Derek
  • 45
  • 1
  • 5
1
vote
1 answer

How to read the integers from the .txt file which contains 2-D array, i am getting java.util.InputMismatchException

so i have to read a matrix from .txt file, which is of the format given below. problemMatrix = [[101, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27, 28, 29, 30], [31, 32, 33, 34, 35, 36, 37, 38,…
1
vote
2 answers

Scanner.next() - Exception in thread "main" java.util.InputMismatchException

Hi guys I am a total newbie. Please help me. The program is: import java.util.Scanner.*; import java.lang.*; public class HexToDecimalFromWeb{ public static void main (String [] args) { Scanner input = new Scanner(System.in); printHeader(); …
Marcin Kulik
  • 845
  • 1
  • 12
  • 28
1
vote
1 answer

Two Dimensional Arrays, Exception in thread "main" java.util.InputMismatchException

I have a little question. I need to read two words in a line for put name and lastname. public void Promedios5(){ Scanner Marbis=new Scanner(System.in); String[] x=new String[5]; double[][] a=new double[5][4]; double[] b=new…
1
vote
1 answer

Exception in thread "main" java.util.InputMismatchException error message

I have tried many different things trying to get this to work. I am sorry for just a lame question I am a total newbie. When I request information from my inFile does it need to be in the order the data is in? This is the inData.txt : 10.20 …
1
vote
1 answer

Java InputMismatchException catch?

I want to be able to handle the exception where anything besides an Int is entered by the user, so that it will throw an exception that can later be handled and a user friendly message be displayed to the user suggesting to enter an int. final int…
Poena
  • 79
  • 1
  • 11