大家好,基本上我是 Java 新手,从 10 月开始,我在做 ComScience。我需要以下帮助,将不胜感激。
注意:我还没有真正制定代码,可以这么说,我想让程序在结构化/注释等之前先运行。UULIB 是大学图书馆的名称。
目标:找出低于平均分的学生的姓名。
这是我在下面用来尝试找到它的代码,但它跳过了第一个 [0] 数组编号并只给了我一个名字。
import uulib.*;
public class Q3
{
public static void main(String[] args)
{
int class_number = Console.getInt("Enter how many students between 1-10");
while (class_number < 1 || class_number > 10)
class_number = Console.getInt("Enter how many students between 1-10");
System.out.println("");
String[] name = new String[class_number];
int[] score = new int[name.length];
for (int i=0; i<class_number; i=i+1)
{
name[i] = Console.getString("Enter Name");
score[i] = Console.getInt("Enter score");
if ( score[i] < average(score))
System.out.print(name[i] + " ");
}
System.out.println(" ");
System.out.println("Average mark = " + Num.format(average(score), 1 ));
System.out.println("Lowset mark = " +lowset(score) );
System.out.println("Highest mark = " +highestValue(score) );
System.out.println("Name of students with highest mark = " );
}
public static double average(int[] nums)
{
double total = 0;
for (int i=0; i<nums.length; i=i+1)
{
total = total + nums[i];
}
return total / nums.length;
}
public static int lowset(int[] nums)
{
int minimum = nums[0]; //sets the first to be the smallest
for (int i = 0; i < nums.length; i++) //goes through your array
{
if (nums[i] < minimum) //checks and replaces if necessary
{
minimum = nums[i];
}
}
return minimum;
}
private static int highestValue(int[] numbers)
{
int highest = numbers[0];
for (int i = 0; i < numbers.length; i++)
{
if (numbers[i] > highest)
{
highest = numbers[i];
}
}
return highest;
}
}