[英]Returning an array from a method in java?
Why I am not getting any output on my output screen?为什么我的输出屏幕上没有任何输出? There should be a reversed array.应该有一个反向数组。
public class Main {
static int[] reverse(int[] array)
{
int[] result =new int[array.length];
for(int i=0,j=array.length-1;i<array.length;i++,j--)
{
result[j]=array[i];
}
return result;
}
public static void main(String[] args) {
int[] newArray = {1,5,9,7,8,0,3,2};
reverse(newArray);
}
}
If you want to see output in your console, you need to send it to either the system's output stream (appropriate in this case), or the error stream.如果你想在你的控制台中看到输出,你需要将它发送到系统的输出流(在这种情况下是合适的)或错误流。
int[] newArray = {1,5,9,7,8,0,3,2};
newArray = reverse(newArray); // <- reuse the variable to save memory
System.out.println(Arrays.toString(newArray));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.