初学,遇一问题不解???请帮帮忙 of course not.应该是,iBuf = parseInt(system.in.read()); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Sorry, 少写一点东西。应该是,iBuf = Integer.parseInt(system.in.read()); 我改了之后:---------------- JDK Debug Build ------------------Compiling D:\JavaPro\t3_10.javaCommand line: "D:\j2sdk1.4.0\bin\javac.exe" -deprecation -g -classpath D:\JavaPro "D:\JavaPro\t3_10.java"The current directory is: D:\JavaProD:\JavaPro\t3_10.java:21: cannot resolve symbolsymbol : method parseInt (int)location: class java.lang.Integer iBuf = Integer.parseInt(System.in.read()); ^D:\JavaPro\t3_10.java:27: cannot resolve symbolsymbol : method parseInt (int)location: class java.lang.Integer iBuf = Integer.parseInt(System.in.read()); ^2 errorsFinished为什么?我在写程序的时候,用的是微软拼音,是不是不能用?只能在纯英文下? sorry,是我的疏忽。用你的程序调试了一下,发现,你原先的程序错误在于,iBuf读进来的是一个char,把他转换成int以后,他就会变成这个char的ASCII数字,例如,输入一个3,iBuf就会是51,所以才会出现你上面所说的最大值是53的情况,因为你输入的最大值是5。为什么会输入5个数字就出来结果了呢?因为再你输入第一个数字以后,你按了一下回车,System.in.read()会把这个也当作字符接受进来,回车就是两个字符,是ASCII码中的13和10。所以建议你不要用这种输入方法,容易出错。该怎么写让我在调试一下,等一会儿告诉你。 以下程序调试通过。import java.io.*;public class t3_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.classCommand line: "D:\j2sdk1.4.0\bin\java.exe" -classpath D:\JavaPro t3_10The current directory is: D:\JavaPro请输入10个整数:1223344556677889901223344556677889901223最小值:7最大值:889Interactive 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就对了。 有关java中异常处理问题!! 求microsoft sdk for java下载地址 我用JDK1.5解释执行程序时提示~~ 谢谢,在线等? 寻求帮助 有偿转让Java即时通信工具源程序及设计文档 关于转型的问题。 谁告诉我为什么这个程序运行三次啊 要将byte数组的内容用string输出,该怎么做? ResultsetMetaData为什么没有表的主键信息 java awt中负责消息分派的函数在哪个类中? 想问一下,大家搞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就对了。