Java中数组的问题

来源:百度知道 编辑:UC知道 时间:2024/05/25 20:48:44
import java.io.*;
public class ex003 {

/**
* Creates a new instance of <code>ex003</code>.
*/
public ex003() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args)throws IOException {
BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in));
float max,min;
float [] a=new float [10];
int i,len=a.length;
String c;
for(i=0;i<len;i++)
{
c=keyin.readLine();
a[i]=Float.parseFloat(c);
//当a[i]放在此处时,输入赋值均正常
}
for(i=0;i<len;i++)
System.out.print(" "+a[i]);//此处的a[i]的值已经不正常了,都是a[0]的值
System.out.println("\n");
max=min=a[0];
for(i=1;i<len;i++)
{
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
System.out.println("max="+max+"\tmin="+min);

}
}
这段代码的实现有问题。错误的地方已经用注释标出来,来个高手帮我找找原因。谢谢了

测试完毕,没问题,下面是结果
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\wf\JavaApplication1\build\classes
compile-single:
run-single:
1.2
2
3
4
5
6
7
8
9
1
1.2 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 1.0

max=9.0 min=1.0
生成成功(总时间:16 秒)

有问题再hi我,pur_e

这两个a[i]不是一个值呀,不正常就对了。

代码确实没看出问题来

应该没有问题,第一个for循环已经为数组赋值了,第二个循环就是输出,不可能只输出第一个值.你再看看.

代码没错,结果也对阿,我不知道你是怎么输入值的。既然做开发就应该知道断点调试,通过断点找出问题。不用断点也应该知道通过代码查问题。