Java学习总结9

课堂小作业:将奇数位的字母大写输出!

实验代码:

package file;
import java.io.*;
public class filetext {
    public static void main(String[] args) throws Exception {
        File f = new File("D:\\text");
        InputStream out = new FileInputStream(f);
        char a[] = new char[(int) f.length()];
        for (int i = 0; i < a.length; i++) {
            a[i] = (char) out.read();
            if (i % 2 == 0) {
                a[i] = (char) (a[i] - 32);
            }
            System.out.print(a[i]);
        }
        out.close();
    }
}

文件内容:

实验结果:

猜你喜欢

转载自www.cnblogs.com/94ha-xc/p/11787735.html