嗨,大家好,基本上我是新來的Java在十月開始,即時通訊科技。我需要幫助,請與以下將不勝感激。如何使用一個數組鏈接到另一個?
注:我還沒有真正奠定了代碼出來沒這麼說我想獲得程序前結構/評論等工作第一。 UULIB是大學圖書館的名稱。
目標:找到低於AVERAGE標記的學生的姓名。
這是我下面使用,試圖找到它的代碼,但它跳過第一[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;
}
}
_「我還沒有真正奠定了代碼出來沒這麼說「_嚴重 - 如果你不在乎,我們爲什麼要這樣做? – npe
儘量縮小你的代碼,讓每個人閱讀起來更容易,並在旁註:人們不要好好地問作業,直接要求答案。 –