读入的当然是Ascii码
char如何置空?置空是什么意思,不就是初始化0吗?
字符串是一个非常重要的概念
char如何置空?置空是什么意思,不就是初始化0吗?
字符串是一个非常重要的概念
解决方案 »
- 请教下byte和char的这2个为什么是相等的
- JTable中如何实现按成绩排序啊,比如:按英语成绩排序?
- Socket TCP协议传输文件有时候不全,求解错和解决方法
- java.sql.SQLException: Invalid parameter binding(s).是什么错误啊?
- 初学者 一个简单的Java程序 自己该了好久还是不能执行 望各位大虾帮帮看看
- Eclipse+CVS,欲哭无泪
- 求大仙解释。。。
- 我想在JButton上贴两张图片,而且有一张是gif动画的,我该怎么实现?
- 算法问题:如何实现一些数字按各自一定的出现概率随机出现?关于赌博机游戏
- java多线程
- 数据库连接池的问题
- Connection、ResultSet不用关闭吗?
字符串操作,在什么语言中都重要。JC pro有不用注册的下载。楼主找找。最好还是学习使用IDE工具
public static void main(String[] args) {
char a[] = new char[50];
int i, j, tottl = 0;
char max = 0;
System.out.println("please enter how many number you will enter:");
try {
// 这是为了取得输入的数字的值(用ASCII码减去'0'的ASCII码
tottl = (int) System.in.read() - 48;
// 这是为了把输入的多余的字符读完
while (System.in.available() > 0) {
//System.out.println(System.in.read());
System.in.read();
}
} catch (IOException e) {
System.err.print(e.toString());
} System.out.println("tottl is " + tottl);
// 因为i是从0开始的,那么应该于tottl - 1结束
//for (i = 0; i <= tottl; i++) {
for (i = 0; i < tottl; ++i) {
try {
a[i] = (char) System.in.read();
} catch (IOException e) {
System.err.print(e.toString());
}
System.out.println(a[i]);
if (a[i] > max)
max = a[i];
}
System.out.println("the max is " + max);
}
}
-----------------------------------
BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
String s = new String();
s = stdin.readLine();
tottl = Integer.parseInt(s);
为什么tottl=(int)System.in.read();
读入的是个ASCII码呢?