NITIKA.. confused

Please review my code, i’m getting wrong answer but on my machine i ran 1000s of testcases easily.

    IO.open();
    InputStream is = System.in;
    int testCases = IO.readInt();
    IO.read();
    char[] buf = new char[50];
    int index=0, lastSpace=-1, tmp=0, count=0;
    while(testCases>0) {
        index=-1; lastSpace=-1;
        do {
            index++;
            buf[index] = Character.toLowerCase((char)IO.read());
            if(buf[index]==' ') {
                if(lastSpace == -1) {
                    buf[0]=Character.toUpperCase(buf[0]);
                    buf[1]='.';
                    buf[2]=' ';
                    index=2;
                    lastSpace=2;
                } else {
                    buf[lastSpace+1]=Character.toUpperCase(buf[lastSpace+1]);
                    buf[lastSpace+2]='.';
                    buf[lastSpace+3]=' ';
                    index=lastSpace+3;
                    lastSpace+=3;
                }
            }
        } while(buf[index] != '\n');
        if(lastSpace==-1) {
            buf[0]=Character.toUpperCase(buf[0]);
            buf[1]='.';
            index=3;
        } else {
            buf[lastSpace+1]=Character.toUpperCase(buf[lastSpace+1]);
        }
        IO.println(new String(buf,0,index-1));
        testCases--;
    }
    IO.close();

why dont you try…
take the input in an array…
take another array…
keep on filling it untill you get an space…if got the space print the second arrays first char in upper and ". ", keep doing this untill you encounter an ‘\0’(null),then print the whole second array with first char in upper and rest in lower. hope its gonna help \m/.

actually jvm on codechef behaving somewhat differently than on my computer.