用java编写控制台输出
这个程序的输出是用java编写控制台输出,java,console,output,Java,Console,Output,这个程序的输出是 class HelloWorld { public static void main(String args[]) { int b; b = 'A'; System.out.write(b); System.out.write('\n'); System.out.write(97); System.out.write('\n'); System.out.write(1889); System.out.write('\n'); } } 下一行如何生成a作为输出 A a a
class HelloWorld {
public static void main(String args[]) {
int b;
b = 'A';
System.out.write(b);
System.out.write('\n');
System.out.write(97);
System.out.write('\n');
System.out.write(1889);
System.out.write('\n');
}
}
下一行如何生成a作为输出
A
a
a
因为
1889%256=97
。有256个ASCII字符,因此使用mod运算符
获取有效字符。根据System.out.write(int)
以系统相关的方式将最低有效字节写入输出。在您的情况下,系统决定将其作为字符写入
System.out.write(1889);
两个数字最右边的八位字节相同。正如@Cricket所提到的,这本质上等同于取你传入的数字的模和256
1889 == 0000 0111 0110 0001
97 == 0000 0000 0110 0001