Last active
May 19, 2019 16:38
-
-
Save theArjun/11d23071abaf8a069be325a2f36cde93 to your computer and use it in GitHub Desktop.
User Input and Printing in Console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 (); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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