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
0
votes
1 answer

BlueJ Scanner won't launch class

import java.util.Scanner; public class Homework { static String aString; public Homework() { } public static void Check(String args[]) { Scanner s = new Scanner(System.in); aString=s.next(); boolean…
0
votes
0 answers

Java detecting strings

I'm trying to make a program in which if you type in "open" to the java console it ends. When I type in open, the if statement below doesn't run. if(input=="open") { System.out.println("You escaped!!"); …
Zachooz
  • 535
  • 11
  • 25
0
votes
1 answer

java- use scanner to read in and process one piece of information at a time

I am trying to use scanner to read in several lines of input at a time. I reckon that there is something wrong with either the way I use the loop, or the way I read in information. Nothing was stored in the output array. I commented my question in…
0
votes
1 answer

java use sanner for i/o and file redirection

I am trying to read input (from keyboard and also with command line file redirection), process the input info. and output it to a file. My understanding is that using the following code, and use command line: java programName< input.txt…
0
votes
4 answers

Java, do while loop runs twice before asking for input again

I am just polishing my java skills and I wrote out this code to play around with keyboard input and do while loops. package Chapter3; import java.io.IOException; public class convertCase { public static void main(String args[]) throws IOException…
Monmon
  • 5
  • 6
0
votes
1 answer

Accessing the same System input stream

I'd like to access the same input stream in 2 different classes in Java. So one class expects an input from System.in while another class writes to System.in. Is this possible? So let's say my first class Test.java expects an input from…
Dave
  • 311
  • 1
  • 5
  • 13
0
votes
3 answers

Read user input from Windows commandline print only from second letter - Java

When I run below lines in Windows command line it does not take the first letter. If I enter 22 it prints only '2' private static String readInput() { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); …
user2771655
  • 982
  • 3
  • 17
  • 35
0
votes
1 answer

BufferedReaders reading System.in across classes

I was wondering why I get a java.io.IOException: Stream closederror when using BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); In 2 different classes. The setup is as follows. public class SomeClass{ BufferedReader…
xrdty
  • 796
  • 2
  • 8
  • 20
0
votes
2 answers

NoSuchElement exception when using Scanner

I'm trying to get input from the console a second time within the program using Scanners but when calling a second Scanner in another method it’s coming up with NoSuchElement exception. If I remove startMenu() from running fileReader() it works,…
0
votes
8 answers

Capitalize every word using Scanner(System.in) Java

This code should allow the user to input a sentence, change it to lower case, and then capitalize the first letter of each word. But I can't get the scanner to work, it just prints nothing. Any suggestions? public class Capitalize { public…
0
votes
0 answers

Redirect System.in on JTextField and make it wait for user's input

I need to create a GUI for an application. I redirected the System.out stream on a JTextArea, but I can't redirect the System.in stream on a separate JTextField. This throws an exception or stop the execution. In the original app, I asked user's…
Stereo89
  • 5
  • 3
0
votes
2 answers

Is there any reason why programmers use a char with System.in.read()?

I notice that the following line of code exists a lot. (For example on this website.) char ch = (char) System.in.read(); // uses a char, and requires a cast. Now to test for a particular character keystroke, or an ASCII value, or an escape…
user2911290
  • 1,296
  • 13
  • 26
0
votes
1 answer

Cannot return result from System.in InputStreamReader

I'm having trouble just return the string of the color. For some reason it will not return the num. Not sure if I need to insert the end of the if statement with an else but I feel like that what the catch statement if for. Main Class package…
Chance Smith
  • 33
  • 1
  • 8
0
votes
0 answers

Java: how to read matrices with unknown size

I need to store the matrix into a[][] from standard input. (System.in) How do I initialize a if the size is unknown Please help, thanks
user2735868
  • 83
  • 1
  • 1
  • 4
0
votes
1 answer

Separating System.Out messages and Scanner (Java)

Is there a way, without using a gui package of any sort, to not have System.out inject itself into the middle of your prompt? The scenario is a threaded program where you send and receive messages to a server. While writing to the server, you get a…
Wuzseen
  • 647
  • 3
  • 12
  • 20