我必须在数组中找到最小的值并打印出来,我有代码,但我无法将它与我的运行程序文件连接,它告诉我,对于我的所有12个示例,RaySmallest中的go(int[])不能应用于(int,int)。
public class RaySmallest
{
public static int go(int[] ray)
{
{
int[] numbers = {};
int smallest = Integer.MAX_VALUE;
for(int i =0;i<numbers.length;i++)
{
if(smallest > numbers[i])
{
smallest = numbers[i];
}
}
System.out.println("Smallest number in array is : " +smallest);
}
return 0;
}
}那是我的跑步者档案
public class SmallestRunner
{
public static void main( String args[] )
{
RaySmallest.go(-88,1,2,3,4,5,6,7,8,90,10,5);
System.out.println();
RaySmallest.go(10,9,8,7,6,5,4,3,2,1,-99);
System.out.println();
RaySmallest.go(10,20,30,40,50,-11818,40,30,20,10);
System.out.println();
RaySmallest.go(65478);
System.out.println();
RaySmallest.go(578,578);
System.out.println();
RaySmallest.go(6,13,-98,100,-987,7);
System.out.println();
RaySmallest.go(9,9,9,13,567);
System.out.println();
RaySmallest.go(-222,1,5,6,9,12,29,1);
System.out.println();
RaySmallest.go(9,8,7,6,5,4,3,2,0,-2,6);
System.out.println();
RaySmallest.go(12,15,18,21,23,1000);
System.out.println();
RaySmallest.go(250,19,17,15,13,11,10,9,6,3,2,1,0);
System.out.println();
RaySmallest.go(9,10,-8,10000,-5000,-3000);
}
}发布于 2017-11-20 00:35:21
您的方法需要一个int[]作为参数:int go(int[] ray)。通过它的一个简单方法是这样做:
RaySmallest.go(new int[] {6, 13, -98, 100, -987, 7});或者,您可以定义go方法,以便它需要多个参数,如下所示:
int go(int... ray)现在你可以像以前一样称呼它了,没有问题:
RaySmallest.go(6, 13, -98, 100, -987, 7);另外,您的代码中还有另一个bug:go()方法没有使用ray参数,而是遍历空的numbers数组。要快速修复,请执行以下操作:
int[] numbers = ray;https://stackoverflow.com/questions/47383554
复制相似问题