报错!帮看看!!
class yun
{
public int area(char [] x,char y)throws
IllegalArgumentException {
for(int i=0;i <x.length;i++)
{
if(x==null)
{
throw new IllegalArgumentException();
}
Arrays.sort(x);
return Arrays.binarySearch(x,y);
}
}
}
class lan
{
public static void main(String [] args)
{
char [] c=new char[5];
c[0]= 'a ';
c[1]= 'b ';
c[2]= 'c ';
c[3]= 'd ';
c[4]= 'e ';
try
{
yun yun1=new yun();
yun1.area(c, 'e ');
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
错误是不能识别这个数组...--------------------Configuration: <Default> --------------------
D:\javawork\lesson1\试题2.java:13: cannot resolve symbol
symbol : variable Arrays
location: class yun
Arrays.sort(x);
^
D:\javawork\lesson1\试题2.java:14: cannot resolve symbol
symbol : variable Arrays
location: class yun
return Arrays.binarySearch(x,y);
^
2 errors
Process completed.
调用前先排序数组我也排了.杂还错?
------解决方案--------------------数组没声明....哪冒出来的
------解决方案--------------------import java.util.Arrays;
------解决方案--------------------Arrays是什么?是引用的java.util.Arrays吗?在文件前面别忘了import java.util.Arrays;(或者java.util.*)
------解决方案--------------------第一,要引入java.util.Arrays这个类
第二,楼主这里的程序似乎是不太正确
class yun
{
public int area(char [] x,char y)throws IllegalArgumentException
{
for(int i=0;i <x.length;i++)
{
if(x==null)
{
throw new IllegalArgumentException();
}
Arrays.sort(x);
return Arrays.binarySearch(x,y);// < <=======return就返回了,以后的就都不执行了。可以把返回值先保存起来,再一起返回。比如用vector
}
}
}