Skip to content

Instantly share code, notes, and snippets.

@theArjun
Last active May 19, 2019 16:38
Show Gist options
  • Select an option

  • Save theArjun/11d23071abaf8a069be325a2f36cde93 to your computer and use it in GitHub Desktop.

Select an option

Save theArjun/11d23071abaf8a069be325a2f36cde93 to your computer and use it in GitHub Desktop.
User Input and Printing in Console
// Program to read input from console and display in console.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
class Main
{
public static void main (String[]args) throws IOException
{
InputStreamReader is = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (is);
String inputString = br.readLine ();
System.out.println (inputString);
is.close ();
br.close ();
}
}
// Shortcut Method
import java.util.*;
class UserInput {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter a line : ");
String userInput = scan.nextLine();
System.out.println(userInput);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment