Menu
Topics Index
...
`

BufferedReaderDemo


If you need explanation Read this topic

If you need Answer Take test on this topic

BufferedReaderDemo
What will be the output of the following program?
import java.io.*;
public class BufferedReaderDemo {
    public static void main(String[] args) throws Exception {
        String s = "NUMBER";
        try {
            StringReader sr = new StringReader(s);
            BufferedReader br = new BufferedReader(sr);
            System.out.print((char) br.read() + ", ");
            br.mark(0);
            System.out.println((char) br.read());
            br.reset();
            System.out.println((char) br.read());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

A. N, U
M
B. N, U
U
C. N, U
N
D. Compilation Error 
E. Runtime Error
Topic: BufferedReader In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans is C

Posted by Raju VarshnEy    2014-09-04 09:06:01


c.

void mark(int )-This method marks the present position in the stream

int read() -This method reads a single character

reset()- his method resets the stream to themost recent mark, or to the beginning of the string if it has never been marked.

hence c is the desired result

Posted by Wajahat Khan    2014-09-04 09:15:29


i think b is the reslt..pic is not clear to me..sovit is dfclt to find the dfrnc in answrs....

here
correct output will be
N,U
U

BCOZ

void mark(int )-This method marks the present position in the streamint read() -This method reads a single characterreset()- his method resets the stream to themost recent mark, or to the beginning of the string if it has never been marked.hence b is the desired result

Posted by Shamee Shamee    2014-09-04 10:25:43


Congratulations Shamee Shamee. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-09-05 05:21:42


© meritcampus 2019

All Rights Reserved.

Open In App