0
public class IndividualProject2 {
public static void main(String[] args) {
int i;
for(i = 0; i < 7; i++){
Scanner gradeInput = new Scanner(System.in);
System.out.println("Enter midterm 1 score: ");
int num1 = gradeInput.nextInt();
System.out.println("Enter midterm 2 score: ");
int num2 = gradeInput.nextInt();
System.out.println("Enter final score: ");
int num3 = gradeInput.nextInt();
}
}
public static char function (int grade){
String[] name = new String[7];
char[] finalGrade = new char[7];
char letter;
if (grade >= 90){
letter = 'A';
System.out.println(letter);
}
else if (grade >= 80 && grade < 90){
letter = 'B';
System.out.println(letter);
}
else if(grade >= 70 && grade < 80){
letter = 'C';
System.out.println(letter);
}
else{
letter = 'F';
System.out.println(letter);
}
for(int counter=0; counter < finalGrade.length; counter++){
finalGrade[counter] = letter;
}
return letter;
}
public static int function (int midtermOne, int midtermTwo) {
int result;
int[] midterm = new int[7];
if (midtermOne > midtermTwo)
{
result = midtermOne;
}
else{
result = midtermTwo;
}
for(int counter=0; counter < midterm.length; counter++){
midterm[counter] = result;
}
return result;
}
public static double function (int num1, int num2, int num3){
double result;
double[] average = new double[7];
result = (num1 + num2 + num3)/3.0;
for(int counter=0; counter < average.length; counter++){
average[counter] = result;
}
return result;
}
}
輸出應該是這樣的http://i.imgur.com/GHo2YS6.png 我有困難創造符合這個特定output.How一個循環做我走在循環中的投入,同時使用三種功能的方法來存儲在值陣列。我對如何做到這一點感到非常不滿。如何使用for循環來簡化將數據存儲在數組中的特定輸出?
邊注:在Java中你真的很少需要使用數組。改用'List'。 – m0skit0 2014-10-17 20:25:48
你在課堂上有多遠?你允許使用Java Collections(例如java.util.List) - 你允許使用額外的類嗎? – 2014-10-17 20:27:15
聽起來像你需要創建一個學生班。 – brso05 2014-10-17 20:28:41