Hello World Using BufferedReader In Java Programming
1. Type this following Java source code in your Java IDE:
/*
* HelloWorldBufferedReader.java
*
* @author codegym, course and tutor, mkyong, petanikode
*
* File Description:
* to read input from keyboard then output to screen
*
*/
// import java packages
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
public class HelloWorldBufferedReader {
public static void main(String[]args) {
// create InputStreamReader object
InputStreamReader isrKeyboardInput = new InputStreamReader(System.in);
// create BufferedReader object
BufferedReader brKeyboardInput = new BufferedReader(isrKeyboardInput);
// create name variable
String strName = null;
try {
System.out.print("Input your name: ");
// System.out.println();
strName = brKeyboardInput.readLine();
System.out.println("Your name is :" + strName);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
2. Save as HelloWorldBufferedReader.java.
3. Compile and run Java source code from above.
Notes
- To see the more clear picture, click on the picture.
- The name in the picture is only for example. You can input the other name.
Bibliography
https://codegym.cc/
https://mkyong.com/
https://www.digitalocean.com/
https://www.educba.com/
https://www.petanikode.com/
https://www.oracle.com/ ( manual book )
Tidak ada komentar:
Posting Komentar