-1
Java數組歇我得在它的字符串數組。在這個例子中,我將使用一個充滿類的數組。而且還有一個數組,其等級通過用戶交互得到填補。現在在特定的序列號
,我就擁有了一切,除了其中最後兩個班這給更多的研究點,那麼剩下的印刷得到雙倍的一部分工作,我想不通這哪裏出了問題。
一些代碼有荷蘭人的名字所以這裏的翻譯列表:
Cijfer是等級
vakken是類
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
final int MAX_ECTS = 39;
int ects = 0;
final int ECTS_VAK = 3;
final int ECTS_PROJECT = 12;
String[] vakkenArray = {"Programming", "Business", "Infrastructure", "Databases", "User Interaction", "Project Fasten Your Seatbelts", "Project Agile Developement"};
double[] cijferArray = new double[7];
for (int i = 0; i < cijferArray.length; i++)
{
System.out.println("Voer A.U.B het cijfer in voor " + vakkenArray[i]);
cijferArray[i] = input.nextDouble();
}
for (int i = 0; i < vakkenArray.length; i++)
{
if (i < 5)
{
if (cijferArray[i] >= 5.5)
{
ects = ects + 3;
System.out.println("Vak/Project:" + vakkenArray[i] + " Cijfer:" + cijferArray[i] + " ECTS Behaald: " + ECTS_VAK);
}
if (cijferArray[i] <= 5.5)
{
System.out.println("Vak/Project:" + vakkenArray[i] + " Cijfer:" + cijferArray[i] + " ECTS Behaald: " + 0);
}
}
else
{
if (vakkenArray[i].equals("Project Fasten Your Seatbelts") && (cijferArray[i] >= 5.5))
{
System.out.println("Vak/Project:" + vakkenArray[i] + " Cijfer:" + cijferArray[i] + " ECTS Behaald: " + ECTS_PROJECT);
ects = ects + 12;
}
else
{
System.out.println("Vak/Project:" + vakkenArray[i] + " Cijfer:" + cijferArray[i] + " ECTS Behaald: " + 0);
}
if (vakkenArray[i].equals("Project Agile Developement") && (cijferArray[i] >= 5.5))
{
System.out.println("Vak/Project:" + vakkenArray[i] + " Cijfer:" + cijferArray[i] + " ECTS Behaald: " + ECTS_PROJECT);
ects = ects + 12;
}
else
{
System.out.println("Vak/Project:" + vakkenArray[i] + " Cijfer:" + cijferArray[i] + " ECTS Behaald: " + 0);
}
}
System.out.println("Totaal behaalde ECTS: " + ects + "/39");
}
這是我的代碼的輸出:
Vak/Project:Programming Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Business Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Infrastructure Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Databases Cijfer:5.0 ECTS Behaald: 0
Vak/Project:User Interaction Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Project Fasten Your Seatbelts Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Project Fasten Your Seatbelts Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Project Agile Developement Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Project Agile Developement Cijfer:5.0 ECTS Behaald: 0
Totaal behaalde ECTS: 0/39
這是應該的:
Vak/Project:Programming Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Business Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Infrastructure Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Databases Cijfer:5.0 ECTS Behaald: 0
Vak/Project:User Interaction Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Project Fasten Your Seatbelts Cijfer:5.0 ECTS Behaald: 0
Vak/Project:Project Agile Developement Cijfer:5.0 ECTS Behaald: 0
Totaal behaalde ECTS: 0/39
如何看項目得到雙面印刷。
不通過''==操作符比較字符串。使用'equals'方法。 ''==比較對象引用(在計算機存儲器地址),而不是字符串對象值。 – 2014-09-19 17:02:17
好吧會的。 我不習慣java的,只是還沒有那麼...... – 2014-09-19 17:03:52
檢查本教程例如:http://www.javabeginner.com/ – 2014-09-19 17:04:41