Menu
Question Index
...

What will be the output of following program?

import java.io.*;

public class PushPullTrain {
    public static void main(String[] args) throws IOException {
        String statement = "It is fun to travel on push pull train.";
        ByteArrayInputStream bais = new ByteArrayInputStream(statement.getBytes());
        PushbackReader train = new PushbackReader(new InputStreamReader(bais));
        char c[] = new char[5];
        read5Characters(train, c);
        train.unread('+');
        read5Characters(train, c);
        train.unread(c, 0, 2);
        read5Characters(train, c);
        bais.close();
        train.close();
    }
    
    public static void read5Characters(PushbackReader train, char[] c) throws IOException {
        train.read(c);
        System.out.print(new String(c).replace(' ', '+'));
    }
}


It+is++fun+++to
It+is+fun+to+tr
It+is++fun++to+
Some other output or Compilation Error
Runtime Error

Doubts

Problems

Topic: Java PushbackReader

Read this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App