Illuminatiiiiii
8/27/2018 - 12:52 AM

Getting Input(BufferedReader)

For Episode 52 of the Java Tutorial. https://youtu.be/WAWlFlQgbT0

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

public class Main {

    public static void main(String[] args) {

        InputStreamReader ir = new InputStreamReader(System.in);//We make this object because BufferedReader requires it as a parameter
        BufferedReader br = new BufferedReader(ir);//The object that will allow us to gather input

        char c; //The variable we will use to store our characters read

        System.out.println("Type some characters. When you are done press x");
        try{
            do{
                c = (char) br.read(); //Cast with a char because the read function returns a ASCII number
                System.out.println(c); //Prints out the letter after storing it
            }while(c != 'x'); //The loop will keep running until the letter x is pressed
        }catch (IOException e){
            System.out.println(e);
        }
        
    }
}