使用是或否的问题在java中循环

时间:2015-09-29 17:13:26

标签: java loops do-while

我在这里遇到一些麻烦,我希望用户能够添加更多信息(成绩和学分),如果他们有更多的课程要添加。我被困住了,希望有人可以提供帮助。谢谢。

import java.util.*;

public class DoWhileDemo 
{
    public static void main(String[] args){
        String name;
        String add;
        double gradePoints = 0;
        double credits = 0;

        Scanner input = new Scanner(System.in);

        System.out.println("Enter Students Name: ");
        name = input.nextLine();
        do {
            System.out.println("Enter class credits: ");
            credits = input.nextDouble();
            System.out.println("Enter letter grade: ");
            gradePoints = input.nextDouble();
            System.out.println("Add another class? (Y/N) ");
            add = input.nextLine();
        } while (add == ("Y"));
    }
}

0 个答案:

没有答案