BufferedReader Code Example Java Programming


Write a Java program by using BufferedReader class to prompt a user
to input his/her name and then the output will be shown as an example below:
Welcome to Cambodia, Bill Gates!
package javaapplication1;

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

public class UBB {

    public static void main(String[] args) throws Exception{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String name;
        System.out.print("Please input your name: ");
        name = reader.readLine();
        System.out.println("Welcome to Cambodia, "+name+"!");