@@ -0,0 +1,1101 @@
+/***%0A *  The API: int read4(char *buf) reads 4 characters at a time from a file.%0A * %0A * The return value is the actual number of characters read. %0A * For example, it returns 3 if there is only 3 characters left in the file.%0A * %0A * By using the read4 API, implement the function int read(char *buf, int n) %0A * that reads n characters from the file.%0A * %0A * Note:%0A *   The read function will only be called once for each test case.%0A */%0A%0Apublic class Solution %7B%0A    /**%0A     * @param buf Destination buffer%0A     * @param n Number of characters to read4%0A     * @return The number of characters read%0A     */%0A    public int read(char%5B%5D buf, int n) %7B%0A        char%5B%5D buffer = new char%5B4%5D;%0A        int readBytes = 0;%0A        boolean eof = false;%0A        while( !eof && readBytes %3C n) %7B%0A            int sz = read4(buf);%0A            if (sz %3C 4) eof = true;%0A            int bytes = Math.min(n - readBytes, sz);%0A            System.arraycopy((buffer /* src */, 0 /* srcPos */, buf /* dest */, readBytes /* destPos */, bytes /* length */);%0A            readBytes += bytes;%0A        %7D%0A        return readBytes;%0A    %7D%0A%0A%7D%0A

add ReadNCharactersGiveRead4.java