Topic: 请帮解读一段代码

  Print this page

1.请帮解读一段代码 Copy to clipboard
Posted by: zxhhero
Posted on: 2004-11-07 16:54


import java.io.*;

class ByteArrayInputStreamReset {
public static void main(String args[]) throws IOException {
String tmp = "abc";
byte b[] = tmp.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(b);

for (int i=0; i<2; i++) {
int c;
while ((c = in.read()) != -1) {
if (i == 0) {
System.out.print((char) c);
} else {
System.out.print(Character.toUpperCase((char) c));
}
}
System.out.println();
in.reset();
}
}
}


输出结果是:
abc
ABC
请问上面红色部分是怎样实现的?感谢先!!

2.Re:请帮解读一段代码 [Re: zxhhero] Copy to clipboard
Posted by: ouyong
Posted on: 2004-11-07 20:36

for 循环了2次,i=0和i=1,i=0时直接输出读入的小写字母,然后reset输入流“in”,第二次循环i=2时将其转换成大写输出。。。

3.Re:请帮解读一段代码 [Re: zxhhero] Copy to clipboard
Posted by: zxhhero
Posted on: 2004-11-07 20:41

Understanded,Thank you very much!!!!!ouyong


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923