charsdemo.java

来自「nanjing university cs 的java课件。 对新手很有用。付」· Java 代码 · 共 25 行

JAVA
25 行
字号
import java.io.*;

public class CharsDemo {
	public static void main(String[] args) throws IOException {
		String tmp = "abcdefghijklmnopqrstuvwxyz";
		byte b[] = new byte[tmp.length()];
		tmp.getBytes(0, tmp.length(), b, 0);
		ByteArrayInputStream n1 = new ByteArrayInputStream(b);
		ByteArrayInputStream n2 = new ByteArrayInputStream(b, 0, 3); // abc
		int c;
		for(int i = 0; i < 2; i++) { // 打印大小写字母表
			while( (c = n1.read() ) != -1) {
				if (i == 0) {
					System.out.print( (char) c);
				}
				else {
					System.out.print(Character.toUpperCase((char)c));
				}
			}
			System.out.println();
			n1.reset();
		} //将读指针移到字节数组的开始
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?