This question already has an answer here: How to determine day of week by passing specific date? 18 answers I need the code to take a date in the format mm dd yyyy (via standard input) and output the week day in plain English. Sample input (mm dd yyy
How can I selectively scan a file into two 2d string arrays? I have a file that looks like this: 2014 fruit apple red 50 30 2015 vegetable spinach green 10 2014 fruit orange orange 100 2014 fruit banana yellow 90 100 2015 vegetable corn yellow 120 I'
I have to write a Double number in a file and later read that file and that Double, but I have an ImputMismatchException. I have debugged the code and the problem is that the PrintWritter that I used to write the file, writes the number whith a dot,
so my main target is this: Write an line of code that enables me to save certain amount of chars (5 in this example is what I tried) into it and how to display them as output, here is where I am currently: public class TryingCharArrays { public stati
I'm interested in using java.util.Scanner. I was reading the docs and saw a line saying A Scanner is not safe for multi threaded use without external synchronization. Can I confirm that this means that two separate Scanner objects in two separate thr
This question already has an answer here: How do I compare strings in Java? 23 answers I have a problem in my programm, I want the user of my programm to write the file he wants to use and then with loops, depending on the word he typed, a file will
So I am having issues with a while loop(been awhile). I am getting a compiling error while trying to set a scanner object to do a program while user input is "y". How do I get this to work? Error is at where choice = Scanner.nextLine import java
My first post here on stackoverflow. The task is: Write a method that shall return a String, the method has no parameters. The method is going to read some word from the keyboard. The inputs ends with the word "END" the method should return this
I'm a beginner at java. I wanted to know how the nextLine() Method discards your current input? For example assume the following code: Scanner input = new Scanner(System.in); int a = input.nextInt(); input.nextLine(); After the input.nextLine() is ex
I'm learning Java and working on some projects for fun. One issue that I have run in to is that when I use a Scanner object Eclipse warns me that: Resource Leak: 'scan' is never closed. So, I added a scan.close(); at the end of my code and that takes
I'm using Eclipse to run the following simple program ( test scanner ) The inputs are mentioned in the Run Configuration -> Arguments section as 23 98 The program does not terminate - hangs without producing a + b import java.io.*; import java.util.*
I want calculate the days between two dates but I have problems with parsing my inputstream ... It works fine if I type my date like "22 1 2013", but I struggle with: 22.1.2013 22-01-2013 01/22/2013 unfortunately I don't know much about regular
I'm relatively new to the world of OOP, and for some reason, the console of IntelliJ and Eclipse doesn't give me an output in the console for the following program. I'm trying to store 12 numbers into an array using scanner and to find the standard d
First, I tried: while (!(in.nextLine().equals(""))) arrayList.add(in.nextInt()); This doesn't work out too well at all for me. Instead, I tried: while (in.hasNextint()) arrayList.add(in.nextInt()); Basically I type numbers separated by whitespac
When parsing a string, we always use StringTokenizer or the split method to parse a string by: , or . or : and so on, My problem is I have a text file that has characters and dots like this : cta...cc.tt..at ta.....tct.c.t. My problem is to parse thi
I know this is simple. How would I take input from my console and store the input into a Set that can later be used to be returned on a Method. This is what I have so far. import java.util.HashSet; import java.util.Scanner; import java.util.Set; publ
package pkgswitch; import java.util.Scanner; public class Switch { public static void main(String[] args) { double subtotal = 0.0; Scanner sc = new Scanner(System.in); outerloop: while(0==0){ System.out.print("Enter subtotal: "); if (sc.hasNextD
This is an assignment i have to complete. Can someone lead me in the right direction? The program compiles but wont run correctly. The error is InputMissmatch exception.Your problem is that you are entering a letter into a float field. In your progra
Code: int size=0; Scanner in = new Scanner(System.in); System.out.println("Enter size of the Graph"); size = in.nextInt(); System.out.println(size); for (int i = 1; i <= size; i++) { Scanner in2 =new Scanner(System.in); while(in2.hasNextInt()
I've never been good with regex and I can't seem to get this... I am trying to match statements along these lines (these are two lines in a text file I'm reading) Lname Fname 12.35 1 Jones Bananaman 7.1 3 Currently I am using this for a while stateme
I have the following file, which I'm using as a test: id=1392 name=Nathan gender=male testempty= testempty2= zip=11111 I'm looping lines and calling the function processLine(String line) on them to process Strings: private String processLine(String l
The code I've currently created stores the first line of the text file, creates a new Vehicle object and puts it in the array at the first position of null, and stores the same line in every null value in the array. I need it to be able to: Store the
I am writing a program that scans text files and then writes each word into a Hashmap. The Scanner class has a defualt delimiter of space. But I ended up having my words stored with punctuations attached to them. I want the scanner to recognize perio
public int Remove(int i, Briefcase c[], String[] m) { int nChoice = 0; boolean inputisok = false; while (inputisok == false) { System.out.print("\tPlease remove " + i + " cases: "); nChoice = input.nextInt(); if (c[nChoice] == null ||
I am very new at java and my be missing something very basic. When i run my code i am trying to add value to accounts created in the code. When i try to run the code i recieve an error that a file cannot be found, but i thought that the file was crea
I have the following code which I'm using to get the user to input an integer, check to make sure the input is valid, and if not, ask for input again. When the code is run, everything works fine until some invalid input is given, at which point the c
Pls I want to keep a count of every word from a file, and this count should not include non letters like the apostrophe, comma, fullstop, question mark, exclamation mark, e.t.c. i.e just letters of the alphabet. I tried to use a delimiter like this,
I'm developing a syntax analyzer by hand in Java, and I'd like to use regex's to parse the various token types. The problem is that I'd also like to be able to accurately report the current line number, if the input doesn't conform to the syntax. Lon
How to obtain a position in file (byte-position) from the java scanner? Scanner scanner = new Scanner(new File("file")); scanner.useDelimiter("abc"); scanner.hasNext(); String result = scanner.next(); and now: how to get the position o
How do you set the delimiter for a scanner to either ; or new line? I tried: Scanner.useDelimiter(Pattern.compile("(\n)|;")); But it doesn't work.As a general rule, in patterns, you need to double the \. So, try Scanner.useDelimiter(Pattern.comp