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
3 answers

Application throws InputMismatchException when string is assigned to double

I am writing a program where I need to check if a string (name) contains any whitespaces or not. Here's part of my program : public static void main() { Scanner sc = new Scanner(System.in) ; String name = "" ; boolean…
1
vote
1 answer

Why am I getting Input mismatch exception error continously

import java.util.*; import java.lang.*; import java.io.*; class Main { public static void main (String[] args) { Scanner sc=new Scanner(System.in); Servicecentre[] ab=new Servicecentre[4]; String n,b; double…
HARINI M
  • 11
  • 1
1
vote
2 answers

java.util.InputMismatchException: For input string: "2147483648"

Below is my code public class ExceptionHandling { public static void main(String[] args) throws InputMismatchException{ Scanner sc = new Scanner(System.in); int a = 0; int b = 0; try { a =…
P Yoga Prudhvi
  • 107
  • 2
  • 3
  • 11
1
vote
3 answers

User put String instead of integer

i am begginer with java and i made a code which the user puts a number but if he writes a string instead of integer it's a error, how can i control the error to show a message to the user? Here's the error: Exception in thread "main"…
1
vote
2 answers

Java not asking for reinput after an InputMismatchException

I have a sample program which registers people for an airline. At the Registration class, on the selectSeats method, I have a try catch block, where the catch statement should catch InputMismatchException in case the user inputs a non numeric…
1
vote
4 answers

why is it giving me an java.util.InputMismatchException when i run this code when I use a text file with the text (shown underneath)

import java.util.*; public void readToolData(String fileName) throws FileNotFoundException { File dataFile = new File(fileName); Scanner scanner = new Scanner(dataFile); scanner.useDelimiter(","); while( scanner.hasNext() ) { …
azzy
  • 21
  • 2
1
vote
3 answers

problem with Java's Scanner: InputMismatchException

I have this code: import java.util.Scanner; public class Maggiore3Valori { public static void main(String[] args) { Scanner scanner = new Scanner("System.in"); int num1, num2, num3; int max; …
1
vote
1 answer

Java scanner input mismatch when using space in input

I am using the scanner in java and am trying to enter a space in my input for option 2 (removing a user from my hashmap) but when I add a space in my answer I get an InputMismatchException. while researching I came across this thread Scanner Class…
Charlie Ansell
  • 451
  • 1
  • 7
  • 22
1
vote
3 answers

InputMismatchException Handling in My Program? - JAVA

Sorry but I'm still very new to Java and I've tried to figure this out with online help. I am trying a try/catch to handle InputMismatchException after "Enter the homework grades for the students" (in case they enter a letter rather than number). It…
1
vote
1 answer

Is it possible to have two catches with the same Exception type from two different methods?

I'm new here and to programming, so sorry if this is too long. I'm sure there's a much easier way to do this, but I'd really like to see if this can get resolved. I'm working on a program that takes user input (double) and converts from Celsius to…
castiyeaux
  • 13
  • 3
1
vote
1 answer

throwing InputMismatchException for second test case

My code is giving InputMismatchException, but not for the single test case. It works fine for the first time and throws the exception for second case. The input it will be getting goes like: The first line of input contains number of testcases T.…
1
vote
2 answers

What does this error code mean? Exception in thread "main" java.util.InputMismatchException

My java code isnt working properly. I keep getting this error message right after it asks the user to enter a R or P. What does it mean? How can I fix it? Exception in thread "main" java.util.InputMismatchException at…
Jessi Kruger
  • 19
  • 1
  • 3
1
vote
2 answers

Q : Doing multiple loops and multiple if-statements and if-else-statements || RENTAL CAR CALCULATOR PROJECT

my instructions on the project were as followed: Instructions: Use a sentinel value loop. To create a basic Rental Car Calculator Ask each user for: Type of vehicle (May use something other than strings, such as: 1 for an economy, 2 for a sedan,…
1
vote
1 answer

JSON mapping in Java from string to string array

I have a class pojo class class A{ private List colors; // getters and setters. } The data comes in json format. Data coming from database is ---- A {"colors":""} The data should come in -- A{"colors":["red"]}. The problem here…
Sasidhar
  • 111
  • 1
  • 1
  • 7
1
vote
1 answer

Read spaces in String as Input Without using NextLine

Discription: I used several scanner statments in below code. First i Read the "Adress" and then "Mobile No." and then some random stuff from user. When i use adress=sc.next() it reads the string value of adress from user(Without space) and go to…
1 2
3
17 18