Tag: 最大值

在2d数组中打印最大数字 – 为什么我的代码打印三个数字

我试图打印出2D数组中最大的数字。 我的问题是我的输出是三个数而不是一个 – 最大的。 为什么? 这是我的代码: public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { int maxRows = 3; int maxCols = 4; int [] onedArray = new int [maxRows]; for (int i = 0; i < maxRows; i++){ onedArray[i] = (int) ((Math.random() * 100) […]

Java – 使用数组查找/打印最小/最大值?

问题: 如何从数组中找到min / max以及语法是什么样的? (( 编辑:开始处理它可能看起来像什么(在这篇文章的底部),但我没有正确的语法 )) 想在我的主类中创建一个方法,以便从一系列学生中找到具有最佳和最差成绩(和打印)的学生,不确定语法在数组中的外观。 Main.java import java.util.*; import java.io.*; public class Main { private static int i=0; public static void main (String[] args) throws IOException { Student[] arrStudents = new Student[7]; Scanner fileInput = new Scanner(new File(“students.txt”)); while (fileInput.hasNext()) { String firstName = fileInput.next(); String lastName = fileInput.next(); int grade = […]