java - 从java中的方法返回一个数组?
问题描述
为什么我的输出屏幕上没有任何输出?应该有一个反向数组。
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);
}
}
解决方案
如果您想在控制台中查看输出,则需要将其发送到系统的输出流(在这种情况下适用)或错误流。
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));
推荐阅读
- c# - 为什么我的服务器 TcpListener 使用本地地址而不使用公共地址?- 例外:请求的地址在其上下文中无效
- javascript - 需要一种使用字符串上的键来识别特定变量类型的方法
- javascript - 学生,老师一个普通的模型还是猫鼬中的两个单独的模型?
- java - SpringBoot + Postman @RequestMapping value = "getImage/{imageName:.+}"
- cassandra - Cassandra 无法将列覆盖为旧值
- java - 如何以编程方式折叠primefaces手风琴面板中的所有面板?
- c++ - 处理时间差异
- google-cast - 使用 HLS 的 AC-3 和 E-AC-3 直通
- python - 在列表上的元组上使用函数在 Google Colab 中有效,但在本地机器上无效
- java - 如何在 Android Studio 中使用 Spinner 获取 RecyclerView 的结果