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.

191 questions
0
votes
1 answer

Cannot invoke "java.io.Console.readLine()" because "c" is null

I am trying to get the input from user by using System.console. However, I get a NullPointerException when I run the following code (I am trying to get input from the user). import java.io.*; public class Systemlearn { public static void…
0
votes
0 answers

Why can't I read the newline characters of a text with an anonymous instance of Scanner(System.in)?

before complaining about "repeated question" read the whole asking, this is different. It's not the same old question about why nextLine() after nextInt() doesn´t work. I got this text on a file: BEAR PARROT FROG HORSE When I copy the text on my…
0
votes
1 answer

Reading System.in character by character without buffering

I know that similar questions have been asked before, but not exactly what I'm asking. To begin with, let me explain my purpose. I'm trying to write a kind of "remote shell" that will take in characters from the console (System.in) on character at…
Lord Moon
  • 23
  • 5
0
votes
2 answers

Writing to System.in from swing ui and reading the input with Scanner

So, I was wondering if Scanner could read from System.in that is set from JFrame. This is what I mean. This is my WriteToSystemIn (JFrame class), which is the GUI part of the program. import javax.swing.*; import java.awt.event.ActionEvent; import…
Jun
  • 3
  • 1
0
votes
1 answer

I am trying to use scanner class by passing java.io.InputStream variable

A question from core java. I am trying to use scanner class by passing java.io.InputStream variable just like System.in. I dissemble java.io.System class and I found that a field is declared as "public static final java.io.InputStream in;" so I also…
Pushkar
  • 11
  • 1
0
votes
3 answers

How to use System.in.read() properly

i tried to use System.in.read() to get the age of the user. My problem is if i write "24" it gives me the output "you are 50 years old". I googled and saw that it has something to do with the encoding. So 24 is mapped to 50. Someone recommended to…
0
votes
1 answer

Can I use bufferedreader after using scanner?

I am testing Scanner and Bufferedreader. I tried to use BufferedReader after using Scanner. However, if I close the scanner, an error occurs. Why is there an error? I tried googling, but I don't understand. import java.io.BufferedReader; import…
0xe82de
  • 3
  • 2
0
votes
1 answer

Alternative for an infinite loop in java while using scanner.hasNext() with scanner argument System.in

Infinite loop using System.in and scanner.hasNext() While taking input from user and storing it in a list newcomer(like me) generally thinks of using Scanner class for input and check for next input from user with hasNext() method as below. But…
AtlasUser5
  • 81
  • 6
0
votes
2 answers

distinguish the working of Scanner, System.in, and next() methods that the Scanner class provides in java?

Scanner scanner = new Scanner(System.in); System.out.println("enter number :"); int number = scanner.nextInt(); System.out.println("Number is " + number); let me go through step by step to explain my understanding, Scanner scanner =…
0
votes
1 answer

What is the analogue for Scanner/System.in if I want to do the output?

If I use the Scanner type for reading System.out, I can easily switch from System.in to some file and thus I can test the methods working with the input. String line; Scanner in = new Scanner(System.in); // reading from the command…
Gangnus
  • 24,044
  • 16
  • 90
  • 149
0
votes
2 answers

Why does this piece of code execute two println statement instead of printing one by one?

Scanner sc4 = new Scanner(System.in); System.out.println("\nEnter the ID of the student you want to update!: "); int id = sc4.nextInt(); System.out.println("Print1!"); String name = sc4.nextLine(); System.out.println("Print2!"); String address =…
0
votes
0 answers

My system.out.printf doesn't show before a scanner's nextLine method

This is my display interface public interface Display { /** *

* Defines how a display decorates each line

*/ public enum Decorator { /** *

* {@code ***}The default string shown around…

logickoder
  • 47
  • 1
  • 6
0
votes
0 answers

Java Scanner for System.in throws java.util.NoSuchElementException: No line found

I know there are a lot of questions about this exception on Stack Overflow but I can't find an answer or an explanation about my particular issue. I have two functions from two different classes. The first one uses the second one. The purpose of…
MuZak
  • 181
  • 5
  • 14
0
votes
1 answer

BufferedReader with new InputStreamReader(System.in) throws an exception Temporarily unavailable resource

In my standalone application I have to read the user input from console in different classes. I created a static class member variable in Installer class public static final BufferedReader buffReader = new BufferedReader(new…
Karthik Suresh
  • 367
  • 7
  • 23
0
votes
1 answer

JAVA Scanner NoSuchElementException: No line found

Sorry for baby question but I am very beginner. Please can you support with concern related to Scanner. [BACKGROUND]: I wrote some code to study Scanner: import javax.swing.JOptionPane; import java.util.Scanner; class Main { public static…
Andrey
  • 1
  • 1