Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 4 months ago. Improve this question
Tag: java.util.scanner
Java validation vehicle registration
I’m trying to do a simple validation for vehicle registration number. It must include “-” Dash/Hyphen symbol. Example: BIR – 5698 It allows Numbers/Letters and Hyphen symbol only. All the other symbols are invalid. ( `~!@#$%^&*()_+=./;,<>”:|[]{} ) My code – Thank you. Your kind help highly appreciated. Answer I’m not sure if what you show as an example registration number
Verifying multiple tokens as Ints with Java
/* My goal is to use the terminal to receive 2 integers and add them together in a Java program. I need to confirm that both terminal entries are ints. If the are, I should proceed to add the ints together. If not, I should print out “Invalid input entered. Terminating…” I am trying to use an if statement with
Trying to stop a Do-While Loop for an application
I’m creating an application for a homework, the problem is that I am trying to create a do-while loop to exit the application (Using the question “Do you want to exit (Y/N)”). To work with the do-while loop, I created a method to store the app and then called the method in the do-while loop, so that when I try
How to take input in java where array length is not defined?
My input is in this format: The array length is not known. I coded it this way: But I am getting this error. Thanks in advance. Answer You should use hasNextInt to check for integer input. Once no more integers, then just use next() to read the player. Example input’s supported output
Scanner for hex-input not working as expected inside loop
I need to solve this problem where i need to convert hexadecimal numbers to decimals. Issue I have compiled it without any errors, but my output came out wrong. Can someone show how to fix these errors? Code Example Input: Expected Output: Output that i got: Answer Your solution is close. Here are changes to make so that it runs
How do I read strings from a file that already contain double quotes?
I have a list of names in a .txt file which are in the format: “Tim”, “Dave”, “Simon” The input will always be single value names in quotes, comma separated and on a single line. I want to read these into String[] names. I have the following code, but the output puts each of them in double quotes, meaning it
Finding elements in array using for loop
I am trying to add Scanner inputs into an array and I am trying to search for the element in an array using a for loop. The for loop looped through all the elements and print out “Not here” when names[i] is not equal to the Scanner input. How do I fix this issue ? Answer
Java: How to use a Scanner to check that input is an integer and is within a specified range
I’m having trouble with my code. What it should do: Check if Scanner “myScanner” is an Integer If it is an Integer, if it is between 1 and 200 (both included) Problem: I need to input an Integer with the correct value twice after the the first guess wasn’t correct. Here is a screenshot of exactly what I mean: Screenshot
Why does it throw an exception when reading int array from file in java
I am trying to read an integer array from a file. the file format is as follows: 893 410 243 264 357 33 793 … … I will later split that array into 4 and calculate it’s sum using MPI, but i can’t seem to be able to read the file. I get this exception: So from what i understand,