java - 基本Java数组编码,查找数组中的最大数
问题描述
编写一个数组的代码,然后对其进行排序并返回最大的数 编写一个程序,其中 main 方法创建一个具有 10 个 int 类型槽的数组。为每个插槽分配一个随机生成的整数。调用一个函数,将数组传递给它。调用
你的主要方法。您的 main 方法应显示返回的数字。使用 Random 对象生成整数。Createwith
Random r = new Random(7);
生成一个随机整数
x = r.nextInt();
到目前为止我写的代码
import java.util.*;
class Lab8Q6
{
public static void main(String[] args)
{
int list[] = new int[10];
System.out.println(returnLargest(list));
}
public static int returnLargest(int a[])
{
Random r = new Random(7);
for (int i=0; i <a.length; i++)
{
a[i] = r.nextInt();
}
Arrays.sort(a);
return a[9];
}
}
解决方案
推荐阅读
- c++ - 在 C++ 中返回指向值类型的指针是一种不好的做法吗
- ios - 在不发布 iOS 应用的情况下获取 App Store ID
- powerbi - Power BI 计算不包括周末和非工作时间的时差
- angular - Angular HttpParams 对象为空
- python - 有没有办法比较python中最新的字母表
- javascript - 是否推荐使用 Typescript 中的下划线?
- javascript - $.getJSON 未捕获的引用错误 $ 未定义
- c# - 如何存储/查询坐标以计算米之间的距离?
- python - 遍历字典以创建实例
- c++ - 使用一个或多个配置文件的多个程序