of course not.
应该是,
iBuf = parseInt(system.in.read());
应该是,
iBuf = parseInt(system.in.read());
解决方案 »
- 求一个 排列组合程序
- j2se
- 关于import
- 请教:我做了一个内部办公系统,内部邮件要求可以通过SMTP和POP3发送和收取邮件
- Process的相关问题
- 菜鸟问题:参数的问题
- 简单程序改错(I/O)~~`~刚来的没分了,昨天全撒水园了
- java能不能开发c/s结构的系统用什么工具??急
- 文件操作,如果给文件加锁???
- 错误信息:Exception occurred: java.rmi.RemoteException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
- 想问一下,大家搞Java,都是用的什么工具?谢谢。
- 如何获得上一组件的的位置信息?
应该是,
iBuf = Integer.parseInt(system.in.read());
---------------- JDK Debug Build ------------------
Compiling D:\JavaPro\t3_10.java
Command line: "D:\j2sdk1.4.0\bin\javac.exe" -deprecation -g -classpath D:\JavaPro "D:\JavaPro\t3_10.java"
The current directory is: D:\JavaPro
D:\JavaPro\t3_10.java:21: cannot resolve symbol
symbol : method parseInt (int)
location: class java.lang.Integer
iBuf = Integer.parseInt(System.in.read());
^
D:\JavaPro\t3_10.java:27: cannot resolve symbol
symbol : method parseInt (int)
location: class java.lang.Integer
iBuf = Integer.parseInt(System.in.read());
^
2 errors
Finished为什么?
我在写程序的时候,用的是微软拼音,是不是不能用?只能在纯英文下?
用你的程序调试了一下,发现,
你原先的程序错误在于,iBuf读进来的是一个char,把他转换成int以后,他就会变成这个char的ASCII数字,例如,输入一个3,iBuf就会是51,所以才会出现你上面所说的最大值是53的情况,因为你输入的最大值是5。
为什么会输入5个数字就出来结果了呢?因为再你输入第一个数字以后,你按了一下回车,System.in.read()会把这个也当作字符接受进来,回车就是两个字符,是ASCII码中的13和10。
所以建议你不要用这种输入方法,容易出错。
该怎么写让我在调试一下,等一会儿告诉你。
{
public static void main(String args[])
{
int iMax = 0;
int iMin = 0;
int iBuf = 0;
int iCount = 20;
try
{
System.out.println("请输入10个整数:");
StringBuffer b = new StringBuffer();
iBuf = System.in.read();
while (iBuf != -1 && iBuf != '\n' && iBuf != '\r')
{
b.append((char)iBuf);
iBuf = System.in.read();
}
iBuf = Integer.parseInt(b.toString());
b = new StringBuffer();
iMax = iBuf;
iMin = iBuf;
for(int iC = 1; iC < iCount; iC++)
{
iBuf = System.in.read();
while (iBuf != -1 && iBuf != 10 && iBuf != 13)
{
b.append((char)iBuf);
iBuf = System.in.read();
}
if (b.length()!=0)
{
iBuf = Integer.parseInt(b.toString());
if(iBuf > iMax)
iMax = iBuf;
if(iBuf < iMin)
iMin = iBuf;
}
b = new StringBuffer(); }
}catch(IOException e) {}
System.out.println("最小值:" + iMin);
System.out.println("最大值:" + iMax);
}
}
Starting application D:\JavaPro\t3_10.class
Command line: "D:\j2sdk1.4.0\bin\java.exe" -classpath D:\JavaPro t3_10
The current directory is: D:\JavaPro
请输入10个整数:
12
23
34
45
56
67
7
889
90
12
23
34
45
56
67
78
89
90
12
23
最小值:7
最大值:889
Interactive Session Ended
你是不是设了要输入20个数?
我有些了一段代码:
import java.io.*;
public class t310
{
public static void main(String args[])
{
int iMax = 0;
int iMin = 0;
int iBuf = 0;
try
{
System.out.println("Please input 10 integers:");
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
iBuf = Integer.parseInt(br.readLine());
iMax = iBuf;
iMin = iBuf;
for(int i = 1; i < 10; i++)
{
iBuf = Integer.parseInt(br.readLine());
iMax = (int)Math.max(iBuf, iMax);
iMin = (int)Math.min(iBuf, iMin);
}
}catch(IOException e) {}
System.out.println("The max number you input is: " + iMax);
System.out.println("The min number you input is: " + iMin);
}
}
在我机子上通过了
我设了iCount=20了(见我的程序)。
抱歉。
改成10就对了。