Using Console to read input (usable only outside of an IDE):

System.out.print("Enter something:");
String input = System.console().readLine();

Another way (works everywhere):

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {
    public static void main(String[] args) throws IOException { 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.print("Enter String");
        String s = br.readLine();
        System.out.print("Enter Integer:");
        try {
            int i = Integer.parseInt(br.readLine());
        } catch(NumberFormatException nfe) {
            System.err.println("Invalid Format!");
        }
    }
}

System.console() returns null in an IDE.
So if you really need to use System.console(), read this solution from McDowell.

Answer from athspk on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › console-readline-method-in-java-with-examples
Console readLine() method in Java with Examples - GeeksforGeeks
June 12, 2020 - Below programs illustrate readLine() method in Console class in IO package: Program 1: ... // Java program to illustrate // Console readLine() method import java.io.*; public class GFG { public static void main(String[] args) { // Create the console object Console cnsl = System.console(); if (cnsl == null) { System.out.println( "No console available"); return; } // Read line String str = cnsl.readLine( "Enter string : "); // Print System.out.println( "You entered : " + str); } }
🌐
Tutorialspoint
tutorialspoint.com › java › io › console_readline.htm
Java - Console readLine() method
package com.tutorialspoint; import java.io.Console; public class ConsoleDemo { public static void main(String[] args) { Console console = null; String name = null; try { // creates a console object console = System.console(); // if console is not null if (console != null) { // read line from the user input name = console.readLine("Name: "); // prints System.out.println("Name entered : " + name); } } catch(Exception ex) { // if any error occurs ex.printStackTrace(); } } }
Discussions

Console.ReadLine(); not working

op is a string and you are comparing it with char. Use double quotes in your if statements. Also read returns an int, I would use readline for all and use a parse to convert it to double.

More on reddit.com
🌐 r/csharp
14
2
February 7, 2020
Console.readInt() doesn't exist?
int speed = Integer.parseInt(System.console().readLine());

Not sure how old that book is but this should be the correct way of doing it. As far as I know readInt isn't a function of console.

More on reddit.com
🌐 r/learnjava
6
4
June 27, 2016
Noob quastion. console.Readline() and console.Writeline()
You can also write Console.Readkey() at the end. The same effect. More on reddit.com
🌐 r/csharp
9
10
May 16, 2018
[C#] Having to input a string twice to make the console function.
I'm trying to write a program that gives you a variety of fruits and vegetables, and giving you some information, and prices according to how many… More on reddit.com
🌐 r/learnprogramming
5
3
January 9, 2016
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › io › Console.html
Console (Java Platform SE 7 )
Console con = System.console(); if (con != null) { Scanner sc = new Scanner(con.reader()); ... } For simple applications requiring only line-oriented reading, use readLine(java.lang.String, java.lang.Object...).
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › User-input-with-the-Java-Console-class
User input with Java's Console class
Introduced in Java 6, Java’s ... ... The readLine() method takes user input through the console window, stores the input data in a String, and echoes the input back to the user as he or she types....
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › io › Console.html
Console (Java SE 21 & JDK 21)
January 20, 2026 - Console con = System.console(); if (con != null) { Scanner sc = new Scanner(con.reader()); ... } For simple applications requiring only line-oriented reading, use readLine(java.lang.String, java.lang.Object...).
🌐
Tabnine
tabnine.com › home › code library
readLine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 24 › docs › api › java.base › java › io › Console.html
Console (Java SE 24 & JDK 24)
July 15, 2025 - Console con = System.console(); if (con != null) { Scanner sc = new Scanner(con.reader()); ... } For simple applications requiring only line-oriented reading, use readLine(java.lang.String, java.lang.Object...).
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.io.console.readline
Console.ReadLine Method (Java.IO) | Microsoft Learn
Reads a single line of text from the console. [Android.Runtime.Register("readLine", "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", "")] public string? ReadLine(string? fmt, params Java.Lang.Object[]? args);
🌐
Scaler
scaler.com › home › topics › readline() in java
readLine() in Java - Scaler Topics
August 5, 2022 - Console and BufferedReader classes contain readLine() method to read a single line of text from two different sources: console and a file.
🌐
GeeksforGeeks
geeksforgeeks.org › java › ways-to-read-input-from-console-in-java
Ways to Read Input from Console in Java - GeeksforGeeks
January 16, 2026 - import java.io.Console; public class Geeks { public static void main(String[] args) { Console console = System.console(); if (console == null) { System.out.println("Console not available"); return; } String s = console.readLine("Enter a string: "); System.out.println("You entered string " + s); } } Input: GeeksforGeeks ·
🌐
Tutorialspoint
tutorialspoint.com › java › io › console_readline_formatted.htm
Java - Console readLine(String fmt, Object... args) method
The Java Console readLine(String fmt, Object... args) method provides a formatted prompt, then reads a single line of text from the console.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › io › Console.html
Console (Java SE 17 & JDK 17)
April 21, 2026 - Console con = System.console(); if (con != null) { Scanner sc = new Scanner(con.reader()); ... } For simple applications requiring only line-oriented reading, use readLine(java.lang.String, java.lang.Object...).
🌐
Baeldung
baeldung.com › home › java › java io › read and write user input in java
Read and Write User Input in Java | Baeldung
January 8, 2024 - To obtain a Console object, we’ll call System.console(): Console console = System.console(); Next, let’s use the readLine() method of the Console class to write a line to the console and then read a line from the console: String progLanguauge ...
🌐
Oracle
docs.oracle.com › en › java › javase › 23 › docs › api › java.base › java › io › Console.html
Console (Java SE 23 & JDK 23)
October 17, 2024 - Console con = System.console(); if (con != null) { Scanner sc = new Scanner(con.reader()); ... } For simple applications requiring only line-oriented reading, use readLine(java.lang.String, java.lang.Object...).
🌐
CodeJava
codejava.net › java-se › file-io › 3-ways-for-reading-input-from-the-user-in-the-console
3 ways for reading user's input from console in Java
July 27, 2019 - Console console = System.console(); if (console == null) { System.out.println("No console: non-interactive mode!"); System.exit(0); } System.out.print("Enter your username: "); String username = console.readLine(); System.out.print("Enter your password: "); char[] password = console.readPassword(); String passport = console.readLine("Enter your %d (th) passport number: ", 2);Advantages: Reading password without echoing the entered characters. Reading methods are synchronized. Format string syntax can be used.Drawbacks: Does not work in non-interactive environment (such as in an IDE).Learn more: Java Console Input Output Examples ·
🌐
JavaBeat
javabeat.net › home › how to use the java readline() method?
How to Use the Java readLine() Method?
January 30, 2024 - Replace the placeholder “<JavaFileName>” with your Java file name. ... In this example, the readLine() method accepts two arguments. The “%S” is a string format that converts the “enter string” message into uppercase letters as shown in the output of the example: //Formatted string String str= System.console().readLine("%S", "enter string : "); System.out.println( "Output : " + str);
🌐
Medium
bnaveen07.medium.com › ways-to-read-input-in-java-from-console-57eae824cd8e
Ways to read input in Java from Console. | by Naveen Kumar | Medium
September 14, 2024 - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BufferedReaderInputExample { public static void main(String[] args) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { System.out.print("Enter your name: "); String name = reader.readLine(); System.out.print("Enter your age: "); int age = Integer.parseInt(reader.readLine()); System.out.print("Enter your height in meters: "); float height = Float.parseFloat(reader.readLine()); System.out.println("Name: " + name); System.out.println("Age: " + age); System.
🌐
Java
download.java.net › java › early_access › loom › docs › api › java.base › java › io › Console.html
Console (Java SE 25 & JDK 25 [build 1])
Console con = System.console(); if (con != null) { Scanner sc = new Scanner(con.reader()); ... } For simple applications requiring only line-oriented reading, use readLine(String, Object...).
🌐
TechVidvan
techvidvan.com › tutorials › java-console
Java Console Class - Ways to read Java Console Input - TechVidvan
April 9, 2020 - The following table shows various methods of Java Console class: Code to take input from user using the Console class: package com.techvidvan.consoleinput; public class Sample { public static void main(String[] args) { // Using Console to input data from user System.out.println("Enter something"); String name = System.console().readLine(); System.out.println("You entered: " +name); } }