import java.io.*;
class ConsoleInput{

    public static void main(String ss[]) throws IOException{

        InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(isr);
        char c=' ';
        System.out.println("Enter Characters And q to Quiet");
        do{

            c=(char)br.read();
            System.out.println(c);
        }while(c != 'q');
    }
}

in upper code this line c=(char)br.read(); get string from user at this point user enter some string like abcdefq and at first iteration jvm checks the a then b then c and so on until jvm finds q (Am I write)

now my question is that there is not increment operator that first check a then increment and check b and so on
is BufferedReader like an array i do not understand its working

Recommended Answers

Buffered reader just has a FIFO stack of characters supplied from the underlying input stream. Each time you call read() it pops the first char and returns it to you.

Jump to Post

but there is a problem read() return -1 and we assign it to char c

Because you need a value to denote EOF/EOS which is not a valid char. Since -1 is not acceptable for a char (char is unsigned after all), read() returns an int.

Jump to Post

All 5 Replies

Buffered reader just has a FIFO stack of characters supplied from the underlying input stream. Each time you call read() it pops the first char and returns it to you.

but there is a problem read() return -1 and we assign it to char c why and what is scnerio

and stack is LIFO not FIFO i think qeues is FIFO

but there is a problem read() return -1 and we assign it to char c

Because you need a value to denote EOF/EOS which is not a valid char. Since -1 is not acceptable for a char (char is unsigned after all), read() returns an int.

and stack is LIFO not FIFO i think qeues is FIFO

OK, it's a FIFO queue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.