如何让程序累积每次用户输入的总点数?

时间:2014-03-28 01:32:21

标签: java arrays

package testB;
import java.util.Scanner;

public class testB {

public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);

        //Declare Variables
        String studentname = "";
        String coursename = "";
        int assignmentsubmitted = 0;
        int submitted = 0;
        int points = 0;
        int pt = 0;
        //Total points worth
        double tpw = 0;
        double score = 0;
        //Total score
        double ts = 0;

        System.out.println("Welcome to My Grade Calculator!");
        System.out.println("");
        System.out.print("Enter candidate name:  ");
        studentname = input.nextLine();
        System.out.print("Enter course name:  ");
        coursename = input.nextLine();

        System.out.println("Enter how many assignments were submitted: ");
        assignmentsubmitted = input.nextInt();
        if (assignmentsubmitted <= 0)
        {
            System.out.print("Must be a number and greater than 0! Try again.");
            assignmentsubmitted = input.nextInt();
        }

        do 
        {       
            int i = 1;
            do
            {
                System.out.println("How many points was assignment " + i + ":");
                i++;
                points = input.nextInt();
        }

它会根据用户输入while (i <= assignmentsubmitted);的分配数递增。 我想要它来计算用户输入的点数,这样我就可以显示它。 points += pt;

1 个答案:

答案 0 :(得分:0)

points += input.nextInt();

点数将包含所有输入的总和。这是你想要的吗?