Questions tagged [system.in]

Predefined stream object attached to the standard input in Java console applications.

It's a static variable in Java's System class. This tag is intended for questions about Java applications that read from the standard input.

177 questions
-1
votes
2 answers

System.in points to JtextArea and using Scanner with it causes application to hang

I've got a JFrame that contains a single JPanel that contains a single JTextArea. I've successfully managed to point System.out to the JTextArea, but when I try to use Scanner(System.in) to parse input from the JTextArea, it doesn't even seem to…
-1
votes
1 answer

Using Scanner - at java.util.Scanner.next(Unknown Source) java.util.NoSuchElementException

My full code is pasted here. Below are the 2 methods that are related to my question. private static boolean playGameAgain() { char playAgain = 'y'; Scanner input = new Scanner(System.in); while(playAgain != 'n') { …
-2
votes
2 answers

InputMismatchError while scanning number

While trying to read a number using below code InputMismatchError is generated: Scanner sc = new Scanner(System.in); while (sc.hasNext()) { long number = sc.nextLong(); // Error here if (number % 2 == 0 && number != 0) { …
-2
votes
1 answer

Java Switch nested for loop will duplicate

I am new to Java and am having trouble with this particular for loop. Everytime I run the loop and enter a number that is not 1 or 2, the loop displays: "Please choose a correct option". What could be the cause of this? public class Kbin { public…
p h
  • 1
-2
votes
1 answer

java System.in How can I use System.in.read()

I am new in java. I should use System.in.read() to solve my program but I don't know ,what does it exactly do? thanks for helping my question : take a number of user. If the number is less than 1, print an error. Otherwise, print the…
-2
votes
1 answer

System.in stop waiting for next line and print output

I have just started solving problems in Hackerrank, and my code did not even pass sample test cases,it gets "Run Time Error". Supposedly, it waits for the new line character on stdin and that is why doesn't output the result. For example, for the…
fiz
  • 389
  • 4
  • 25
-2
votes
1 answer

java, getting user input through scanner and system.in

how can I give a condition on an input from "system.in" that will halt the program until the right value is inserted? for exemple, I'm waiting for an INT from the user, 1,2,3,4 or 5 the user inputs "hello" how can i give the user a message of…
Tzur
  • 3
  • 2
-3
votes
2 answers

Scanner + System.in stop condition

I'm reading a file with Scanner + System.in. My command in Linux looks like: cat -A test.txt | java -jar test.jar I'm reading input like: Scanner input = new Scanner(System.in); while (input.hasNextLine()) { String log_line =…
Serhiy
  • 3,846
  • 2
  • 33
  • 62
-3
votes
2 answers

Determine wether input is an int or a string

I have been using Scanner and System.in recently, but I am not able to find a code that can judge whether the input is a String or an integer and then treat it accordingly. Does anonye know a way?
-3
votes
3 answers

Using an if statement with a system.in scanner

I'm not sure how to explain this problem but please someone help me. I want to have a program to where if a word is typed into the keyboard, I have an if statement that makes it so that when that word is entered it prints out a sentence on the…
JP96
  • 1
  • 1
-3
votes
1 answer

Can I do StringTokenizer stk = new StringTokenizer(System.in)?

In Java, can I do StringTokenizer stk = new StringTokenizer(System.in); ? I am wondering if I can expect to collect the input stream as a sting like that or is there a better way of getting the user input converted to a string before I can use it…
Alain
  • 157
  • 1
  • 2
  • 13
-4
votes
2 answers

eclipse junit system.in java

I am trying to create a junit test on a method that calls for a user input using scanner and System.in. The method being tested looks like this: public void setUserAnswer(){ Scanner input = new Scanner(System.in); userAnswer =…
1 2 3
11
12