输入和出错提示如下:thenumberofthearray:3shuru:32eee3hah3.0hah2.0thydddddddd:thydddddddd:thydddddddd:[3.0,2.0,3.0]Exceptioninthread"main"java.lang.ArrayIndexOutOfBoundsEx...
输入和出错提示如下:the number of the array:
3
shuru:
3 2 e e e 3
hah3.0
hah2.0
thydddddddd:
thydddddddd:
thydddddddd:
[3.0, 2.0, 3.0]
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at oneArrayLib.FindMinValue(java1.java:12)
at java1.main(java1.java:55)
代码如下:
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.Arrays;
class oneArrayLib {
double a[];
public oneArrayLib(double arr[]){
a=new double[arr.length];
System.arraycopy(arr, 0, a, 0, a.length);
}
public void FindMinValue(){
double temp=a[3];
int num=0;
for(int i=0;i
if(a[i]
temp=a[i];
num=i;
//System.out.println(temp);
//System.out.println(a[i]);
}
}
System.out.println(temp);
System.out.println(num);
}
}
public class java1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count;
System.out.println("the number of the array:");
Scanner cc=new Scanner(System.in);
count=cc.nextInt();
double s[];
s=new double[count];
System.out.println("shuru:");
int i=0;
//String cost="34 5 45 65";
Scanner a=new Scanner(System.in);
//Scanner a=new Scanner(cost);
while(a.hasNext()){
try{
s[i]=a.nextDouble();
if(i==s.length-1) break;
System.out.println("hah"+s[i]);
i++;
}
catch(InputMismatchException exp){
String t=a.next();
System.out.println("th3ydddddddd:");
}
}
System.out.println(Arrays.toString(s));
oneArrayLib array=new oneArrayLib(s);
array.FindMinValue();
}
}
展开