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
0
votes
2 answers

Why does this try statement use the catch statement?

import java.util.Scanner; import java.util.InputMismatchException; public class bank { public static void login() { double balance; try { boolean subtract; boolean amounttaken; // This is to…
0
votes
1 answer

Getting exception in thread "main" java.util.InputMismatchException

I am trying to take input one by one and then trying to perform operations over them. Following my code. import java.util.Scanner; public class PlayerRoster { public static void main(String[] args) { Scanner scnr = new…
0
votes
1 answer

my scanner stopped working after a couple of runs and gives me the java.util.InputMismatchException: For input string: "7642874781"

After the name, Charlie is printed out it throws the input mismatch exception and says I'm entering a string into the int scanner but it really is a number so why is it telling me it's a string? This is my textfile that the scanner is reading…
0
votes
1 answer

HttpMessageNotReadableException and MismatchedInputException

I have a game in java called "Scotland Yard". In backend it is coded with java and frontend is coded with angular. From the beginning the game contained enums as transportation types but then our assignment were to have dynamically transport types.…
Mohammed
  • 195
  • 1
  • 3
  • 12
0
votes
1 answer

InputMismatch when using Scanner in from file

Good evening. I am trying to read doubles from a file and put them into a double array. The way I have approached this is to use a Scanner. This is my code public static void decryption(int n, int d) throws IOException { String encFile =…
0
votes
3 answers

The Program still throws an InputMismatchException and exits even though its been caught

I am just learning Java and I'm struggling with Exception handling. I am trying to write a quick program that takes some inputs and exports them converted into different units. I am using Scanner to take the input and I'm trying to protect against…
Jack27696
  • 21
  • 2
0
votes
1 answer

Multiplication of two 64 digit number_Gettin Input Mismatch Exception

public class Karatsubamultiplication { public static void multiply(long ac , long ad, long bc, long bd, long digits) { double mul=0; mul = Math.pow(10, digits) *ac + Math.pow(10, digits/2)*(ad+bc)+bd; …
0
votes
1 answer

I am having trouble with InputMismatchException in Java

I am having trouble running my code as it is giving me Exception in thread "main" java.util.InputMismatchException. Can you please help me out. Here is the code: import java.io.*; import java.util.*; import java.text.*; import java.math.*; import…
0
votes
1 answer

My perfectly working Java code throws an exception in IntelliJ IDEA

I've been using eclipse and OnlineGDB for my Java works. I recently started to use IntelliJ IDEA and I'm enjoying this a lot. But i tried to work one of my simple projects in IntelliJ IDEA about file operations. But it gives me an error during…
Gökhan Uçar
  • 191
  • 15
0
votes
0 answers

Read formatted text from file using a scanner

I would like to read a file with the following format using a Scanner. integer,integer integer,integer ... First I added, scanner.useDelimiter(","). Then I used, scanner.nextInt() twice for the two integers and used scanner.nextLine() to get the…
0
votes
1 answer

i want to print invalid input when the catch block is run but it is not happening.Please help me out

i want to print the content in the catch block if an input mismatch occurs. i have written the code for the class Marathon whose object is created here. help me out import java.util.InputMismatchException; import java.util.Scanner; public class…
0
votes
2 answers

Issue with nextFloat in java

I need it to skip the first line of the text file and then the first two columns of the table. So far I have: }public static float [][] read_data(String strFileName){ float[][] fileread = new float[ROWS][COLUMNS]; File filedata = new…
0
votes
2 answers

Can't catch InputMismatchException

So I've been working on an assignment that requires us to build a "Patient manager", that bases which patient to be treated first based on the emergency level. The main issue I'm running into is that when the user enters something apart from a…
Gabrielp
  • 15
  • 1
  • 5
0
votes
1 answer

Program to continually ask for double values, using sentinel-controlled loop

So I am working on a Java program that continually ask the user for double values. I am supposed to use a sentinel-controlled loop with sentinel value of -999. I need to use an ArrayList while using try/catch block to handle inputMismatchExceptions,…
0
votes
1 answer

Getting InputMismatchException when trying to enter a string with whitespaces

I have a task: 5-8) (Find the highest score) Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the name of the student with the highest score. When I run this code with…
qwitz
  • 3
  • 3