是否可以在 Java 中进行此输出?在询问每个学生的输入成绩时使用循环语句,然后使用天花板来确定谁的成绩最高。
Student Number Grades
Student 1 _
Student 2
Student 3
Student 4
Student 5
Student 6
Student 7
Student 8
Student 9
Student 10
成绩最高的学生是:(例如)学生 8
是的,您可以使用循环:
Scanner scan = new Scanner(System.in);
double max = -1; // grades can't be negative
int maxStudent = 0;
double[] grades = new double[10];
for (int i = 1; i < grades.length; i++) {
System.out.println("Please enter grade for Student "+i);
grades[i] = scan.nextDouble();
if (grades[i] > max) {
max = grades[i]
maxStudent = i;
}
}
Math.ceil(double a)
Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer. So unless you're trying to round up, you won't need ceil. Although to answer the title question, you can use Math.ceil
on an input string, assuming the string can be parsed into a double.
For instance, these are all true statements:
Math.ceil(99) == 99.0
Math.ceil(99.01) == 100.0
Math.ceil(99.99) == 100.0
Can ceiling only be used in one number? or it can be used with multiple numbers like that.
You can not use Math.ceil
on any sort of collection to find the highest value as you wish to do. Loop through all values an keep track of the highest