I’m working on a .xml file generator. It works by asking the user to input 5 different values and then using them for generating a .xml data container. This is the code: I want the program to detect when someone inputs an empty string by pressing the enter key with no written text and print a message asking the user
Tag: java.util.scanner
Output is not showing for second array in Java
I’m a beginner in Java programming and I created a program that accepts 10 numbers as input from users and prints them. The first section is using for loop and the second section is using while loop. The first section works properly and the second section isn’t displaying output. Could anybody help me? } Answer You are not resetting variable
Java scanner input loop throwing No Such Element exception after first loop
I want a program that repeatedly prompts the user to input a number and then prints whether that number is prime or not. This works once, then on the next iteration it gives a No Such Element Exception before the user can enter another input. I’ve tried using IF statements with hasNext() or hasNextInt() but those never seem to be
Why do I have to write twice to add an input in the Arraylist?
I’m trying to get some input from the user and store them into arraylist. The problem is I have to write the item twice to add an item into the list. I can’t figure out why! Answer Every time you write readLine(), a line is read. In this loop, There are two occurrences of readLine(), so two lines are read
Can’t input anything after the User obj3 = new User(); part
i cannot input anything after the User obj3 part. Can anyone help me on what’s wrong with it? i didn’t know what to do already. Answer It looks like a problem with the way you used Scanner. I tried to run this myself (with User and Administrator commented out), and it skipped over the ID: and Password: inputs. Scanner has
Extraction of string and integer from txt
I’m trying to make a simple scanner reader to read from a txt stored in C:UsersjamesDesktopprojectfiles and it’s called data “data.txt”, the thing is that the information stored is like this: So as you can see the spaces between the string and the integer that I want o extract are random. I was trying to make this: But the split
Cant find pattern with Scanner in Java 8
I’m working with Java 8 on eclipse and trying to use regex to detect strings in a file, but I’m not detecting anything. I’ve tested the regex on its own and it successfully match’s strings in the file …
Java scanner.nextLine() not reading long line with 259094 characters
I want to read an xml file as a String in Java so that I can encrypt it. My current approach is to treat it like a txt file. My problem is that the third line in the xml file is 259094 characters long and for some reason, the scanner’s nextLine() method is only reading up to 131072 characters into
Should a Scanner only be instantiated only once? if that’s the case why so?
I know I’m going out on a limb here, but I just can’t seem to understand why can’t we just create an instance of the Scanner class twice. I’ll add an example just in case. And I get a runtime error which looks something like this I know it doesn’t make sense to create a new object again of the
How to implement Body Mass Index (BMI)in Java
My problem is how can I implement without the Scanner method and with Math.round and Math.pow? Here is my code: My another idea was It is only for a certain value. In my case with a weight of 75.0 and size 178.0 Answer It’s up to developer to choose how to initialize parameters. If don’t want to use scanner the