循環這些語句的任何幫助。我對此很陌生,而且遇到了一些麻煩。我正在努力做到這一點,以便在給予班級平均分數之前,成績簿將五個孩子的成績。只需要幫助循環。循環輸入和語句的列表
import java.util.Scanner;
public class gradebook {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
float discussionweight, hwweight, examweight, discussion, hw, exam, finalaverage, again;
Scanner scan = new Scanner(System.in);
System.out.print("Enter the students name: ");
String student = scan.next();
System.out.print ("Enter the weight of the discussions as an integer: ");
discussionweight = scan.nextFloat();
// Prompts for the discussions grade
System.out.print ("Enter the score of the discussion as an integer: ");
discussion = scan.nextFloat();
// Prompts for the weight of the homework grade in an integer
System.out.print ("Enter the weight of the homework as an integer: ");
hwweight = scan.nextFloat();
// Prompts for hw grade
System.out.print ("Enter the hw grade: ");
hw = scan.nextFloat();
System.out.print("Enter the weight of the exam as an integer");
examweight = scan.nextFloat();
System.out.print("Enter the exam grade");
exam = scan.nextFloat();
// Calculate and print the final, weighted average.
finalaverage = (((discussionweight * discussion) + (hw * hwweight) + (exam * examweight))/100);
if (finalaverage >= 90)
System.out.println(student +"'s " + "final grade is an A.");
else if (finalaverage >= 80)
System.out.println(student +"'s " + "final grade is a B.");
else if (finalaverage >= 70)
System.out.println(student +"'s " + "final grade is a C.");
else if (finalaverage >= 60)
System.out.println(student +"'s " + "final grade is a D.");
else if (finalaverage >= 10)
System.out.println(student +"'s " + "final grade is an F.");
System.out.println ("The final average is "+ finalaverage);
System.out.println ("Would you like to continue? Enter 0 to exit and anything else to continue.");
String again = scan.nextFloat();
while (again != 0) {
finalaverage += again;
}
}
如果你想整個事情循環 - 就像從'浮discussionWeight ...''直到再次字符串= scan.nextFloat()',那麼你應該附上所有在循環塊中的那些語句。因此,底部的'while'循環應該包含所有上面的語句。 – jackarms 2014-08-31 04:19:43
嗯 - 對於你的程序不會編譯 - ''再次'被聲明兩次... – jdphenix 2014-08-31 04:21:19
我建議你把它分解成更易於管理的方法。 – 2014-08-31 05:18:24