263 questions
0
votes
0
answers
33
views
How to handle non-numeric input when using scanner.nextInt() in Java [duplicate]
I’m learning Java and testing basic input handling.
I wrote the following simple program:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner ...
0
votes
0
answers
75
views
Java Scanner nextBigDecimal throwing InputMismatchException exception
I wrote some simple Java code to take input from the console (using Eclipse 2016 IDE) to assist with iterating through a text file and outputting a file in SWIFT MT940 statement structure. For the ...
0
votes
0
answers
31
views
how can i limit the user to a certain input [duplicate]
Hi I'm trying to learn java
This a simple program that stores a patient's blood details, well in any case how can i keep the program accurate by means of returning an error message if the input was ...
0
votes
0
answers
39
views
I keep having InputMismatchException error every time I type the name of the person in the Scanner?
what is the problem with my code and why do I have the InputMismatchException error every time I type the name in the console ?
Scanner sc = new Scanner(System.in);
System.out.println("...
0
votes
1
answer
33
views
How to store values in custom object array using Scanner in Java?
I was given an exam, where I had to create a class and after that, I had to write two functions in which the input parameter is an object Array and took the values from user input. Below is the code ...
0
votes
1
answer
95
views
How do I message an end user that they are entering the wrong input and/or format without getting an Exception/Crash?
"Eclipse IDE for Java Developers (includes Incubating components) Version: 2023-03 (4.27.0)"
Intro to Programming using Java Section 3.5.3
Sorry for the very long post. This is my first post ...
0
votes
0
answers
49
views
InputMismatchException when attempting to run program again in do while loop
Having successfully created a policy holder and writing the information to csv I try to run the program again using a do while loop but receive an inputmismatchexception after typing surname.
Can ...
0
votes
2
answers
303
views
Try/Catch loop issues for paint calculation
The goal is to make code that can handle exceptions and keep going. I made a try/catch for typing string instead of numbers, but when I test it, it prints the catch output but then has these errors :
...
-1
votes
2
answers
4k
views
Why Mileage tracker gives InputMismatchException?
Given the MileageTrackerNode class, complete main() in the MileageTrackerLinkedList class to insert nodes into a linked list (using the insertAfter() method). The first user-input value is the number ...
0
votes
0
answers
19
views
Input Mismatch exception Java [duplicate]
I am getting the input mismatch exception error on my code.
I am getting error at the Engine displacement line.
Scanner scanner = new Scanner(System.in);
Car[] arr;
System.out.println(&...
0
votes
2
answers
31
views
Difference between two codes and InputMismatchException
I am a newbie with java and the class scanners.
I have two Codes and I dont get the point why one of them throws a InputMismatchException.
I look forward to the answers.
Here both codes:
1st one with ...
0
votes
2
answers
388
views
I am doing my homework and I stuck in one question. I am new to java. can you help me? [duplicate]
The question is:
Create a class person with attribute name, age and gender. Create an array of the person to hold 10 person instances. Display the information stored on the person instance in the ...
0
votes
1
answer
29
views
InputMismatchException occurred when inputing String and Double values
Here is my problem I've been struggling with:
I want the input to be in this form:
1
So I wrote the code like this. Unfortunately, it either gives me an InputMismatchException at line 6 or cannot ...
2
votes
2
answers
388
views
Scanner#nextDouble fails to parse 5.2 (InputMismatchException) [duplicate]
Problem
I was messing around with Java today, and bumped into something that I can't fix by myself. I'm trying to get a double value from scanner but always get this error:
Exception in thread "...
0
votes
1
answer
69
views
InputMismatchException in a scanner to get data from txt file
I'm trying to read the highscores of a game from a txt file and put them into an array so that another section of the program can detect a high score. Earlier I had everything declared as Int and it ...
0
votes
1
answer
616
views
input mismatch exception while using space in between words
I'm working on a project and I already finished it, I have really simple problem which makes me really confused. I'm trying to ask a user to enter a number from a menu and depending on that different ...
0
votes
4
answers
3k
views
How to prevent wrong user input on a variable?
Im currently trying to build a code that prevents wrong user input (storing a char/string to a integer, e.g.) but Im not being able to make it to work...
public static void main(String[] args) {
...
0
votes
1
answer
62
views
How am I catching an InputMismatchException here?
I'm trying to catch InputMismatch exceptions and display a message that tells me where the exception occurred and what type of input is required. I need this to loop until the correct input is entered....
0
votes
1
answer
29
views
Do I have to change my code to use a scanner in order for inputmismatch exception to work?
My InputMismatchException isn't working, as when I put in something like a double into the input, instead of the exception output message, it gives me:
Exception in thread "main" java.lang....
-1
votes
1
answer
93
views
How to resolve InputMismatchException in Java
I'm trying to read a .adi file that has a line format of String, Int and Double.
For example:
Ford,Fusion,2010,85254,12855.58
For the code, I'm required to use a try-catch statement and the method ...
0
votes
2
answers
988
views
Stop infinite Loop when handling invalid user input - Java [duplicate]
I'm fairly new to programming and I'm having trouble with my program continuously looping when I try to handle a InputMisMatch exception.
I have a menu which takes in user input and then uses a switch ...
0
votes
2
answers
53
views
I keep getting an InputMismatchException even though all types are correct , what should ido?
import java.util.Scanner;
public class Messdaten {
public static double temperaturInDurchschnitt(Scanner sc){
int year= 0, month= 0 , day= 0;
String discription = "";
...
-1
votes
1
answer
64
views
Program is giving me a "Exception in thread "main" java.util.InputMismatchException"
This is the code I am using for my program
import java.util.*;
import java.io.*;
import java.util.ArrayList;
/**
* This program will read the information from the
* txt file and will organize ...
0
votes
1
answer
47
views
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 ...
0
votes
1
answer
30
views
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) ...