Home » JAVA Programming » Files and I/O » Question
  1. What is the output of this program?
    import java.io.*;
    public class Chararrayinput_Example
    {
    public static void main(String[] args)
    {
    String object = "InterviewMania";
    int len = object.length();
    char array[] = new char[len];
    object.getChars(0, len, array, 0);
    CharArrayReader chararray = new CharArrayReader(array);
    CharArrayReader chararray0 = new CharArrayReader(array, 1, 4);
    int K;
    int L;
    try
    {
    while((K = chararray.read()) == (L = chararray0.read()))
    {
    System.out.print((char)K);
    }
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    }
    }
    1. Interview
    2. InterviewMania
    3. Mania
    4. All of these
    5. None of these
Correct Option: E

No output is printed. CharArrayReader object input1 contains string “InterviewMania” whereas object chararray contains string “nter”, when while((K=chararray.read())==(L=chararray.read())) is executed the starting character of each object is compared since they are unequal control comes out of loop and nothing is printed on the screen.



Your comments will be displayed only after manual approval.