Reading Input from User Using BufferedReader in Java

0 comments

Below I will give you an example script for reading the input string typed by the user. In this example I am using JCreator where this application can compile and run pulled we type java file, without opening Commandprompt. But if you do not have JCreator please use Notepad, because it just wrote.
On this occasion I will use the BufferedReader, direct me give you an example script:
 
------------------------------------------------------------------------------------------
import java.io.*;
public class inputbuffer {
public static void main (String [] args) {
System.out.println("Masukkan nama anda : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String nama = null;
try {
nama = br.readLine();
}catch (IOException ex) {
System.out.println("System Error!");
System.exit(0);
}
System.out.println("Terima kasih " + nama);
}
}

------------------------------------------------------------------------------------------

Once the script is written above then press F5, then the script will run on JCreator:
 
 
Input / entry your name, example: iToru. Kaan then the output looks like this:


Share this article :

Post a Comment

Ads

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Share It Out - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger