Enter the date via standard input. Output day of the week.

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

Is the Java scanner not secure?

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

Error in the new scanner

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

Loop scanner

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

Java returning the entered text

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

how does nextLine reject the entry?

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

Java & mdash; Closing the scanner and resource leak

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

Debugging - read drive input problem

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.*

No results in the console, probably a logical error

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

How to check if the input key has been pressed into a scanner?

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

How to store 6 integers of the scanner console in a set

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

Class Scanner ~ hasNextDouble ();

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

The program compiles but does not work

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

Why does not my program come out of the while loop?

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()

Statement of Regular Expression

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

Detect if the scanner has no follow-up

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

How to use the delimiter to isolate words (Java)

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

Help with entries using the scanner

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 ||

My Java code is faulty, but I do not understand why

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

Why does this user input method not work?

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

Analysis of newline Java Scanner with regex (Bug?)

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

Java Scanner Question

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