Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
输入Y或N-Java后,输出会不断重复,不会循环,也不会结束程序_Java_Loops_Do While - Fatal编程技术网

输入Y或N-Java后,输出会不断重复,不会循环,也不会结束程序

输入Y或N-Java后,输出会不断重复,不会循环,也不会结束程序,java,loops,do-while,Java,Loops,Do While,我有一个问题,它循环相同的输出,即使我输入了正确的输入结束循环。这是不断重复无效输入的输出。请重新输入!你想输入另一个学生的分数吗?[Y/N]。我已经查看了代码中可能出现的错误,但我无法找出代码在哪里出错,从而导致错误发生。下面是完整的代码 import java.util.Scanner; public class tutorial { @SuppressWarnings("empty-statement") public static void main

我有一个问题,它循环相同的输出,即使我输入了正确的输入结束循环。这是不断重复
无效输入的输出。请重新输入!你想输入另一个学生的分数吗?[Y/N]
。我已经查看了代码中可能出现的错误,但我无法找出代码在哪里出错,从而导致错误发生。下面是完整的代码

import java.util.Scanner;

public class tutorial {
    @SuppressWarnings("empty-statement")
    public static void main (String args[]){
        Scanner input = new Scanner(System.in);
        String id, inpTutorial, inpAssignment, inpTest, inpProject, inpFinalExam, reenter = "", enter = "", reenterAgain = "", enterAgain = "";
        int A = 80, B = 65, C = 50, D = 40, F = 0, bPlus = B + 5, cPlus = C + 5;
        Double tutorial = 0.0, assignment = 0.0, test = 0.0, project = 0.0, finalExam = 0.0, tutorialMarks = 0.0, assignmentMarks =0.0, testMarks = 0.0, projectMarks = 0.0, finalExamMarks = 0.0;
        double totalMarks = 0.0;       
        
        do {
        
        do {
            System.out.println("Please enter ID");
            id = input.next();
            
            if(id.isEmpty()) {
                System.out.println("ID should not be empty!\n");
            }
            
            else {
                
                do {
                    System.out.println("Please enter tutorial marks");
                        inpTutorial = input.next();
                        tutorial = Double.parseDouble(inpTutorial);
                   
                    
                    if (tutorial < 0) {
                        System.out.println("Tutorial marks cannot be a negative!\n");
                    }
                    
                    else if (tutorial > 100) {
                        System.out.println("Tutorial marks can only be 100%\n");
                    } 
                    
                    else if (tutorial == null) {
                        System.out.println("Tutorial marks must have a value!");
                    }
                    
                    else {
                        do {
                            System.out.println("Please enter assignment marks");
                            inpAssignment = input.next();
                            assignment = Double.parseDouble(inpAssignment);
                   
                    
                    if (assignment < 0) {
                        System.out.println("Assignment marks cannot be a negative!\n");
                    }
                    
                    else if (assignment > 100) {
                        System.out.println("Assignment marks can only be 100%\n");
                    } 
                    
                    else if (assignment == null) {
                        System.out.println("Assignment marks must have a value!");
                    }
                    
                    else {
                        
                        do {
                            System.out.println("Please enter test marks");
                            inpTest = input.next();
                            test = Double.parseDouble(inpTest);
                   
                    
                    if (test < 0) {
                        System.out.println("Test marks cannot be a negative!\n");
                    }
                    
                    else if (test > 100) {
                        System.out.println("Test marks can only be 100%\n");
                    } 
                    
                    else if (test == null) {
                        System.out.println("Test marks must have a value!");
                    }
                    
                    else {
                        
                        do {
                            System.out.println("Please enter project marks");
                            inpProject = input.next();
                            project = Double.parseDouble(inpProject);
                   
                    
                    if (project < 0) {
                        System.out.println("Project marks cannot be a negative!\n");
                    }
                    
                    else if (project > 100) {
                        System.out.println("Project marks can only be 100%\n");
                    } 
                    
                    else if (project == null) {
                        System.out.println("Project marks must have a value!");
                    }
                    
                    else {
                        
                        do {
                            System.out.println("Please enter final examination marks");
                            inpFinalExam = input.next();
                            finalExam = Double.parseDouble(inpFinalExam);
                   
                    
                    if (finalExam < 0) {
                        System.out.println("Final examination marks cannot be a negative!\n");
                    }
                    
                    else if (finalExam > 100) {
                        System.out.println("Final examination marks can only be 100%\n");
                    } 
                    
                    else if (finalExam == null) {
                        System.out.println("Final examination marks must have a value!");
                    }
                    
                    else {
                        tutorialMarks = (tutorial/100)*10;
                        assignmentMarks = (assignment/100)*10;
                        testMarks = (test/100)*20;
                        projectMarks = (project/100)*20;
                        finalExamMarks = (finalExam/100)*40;
                        
                        totalMarks = tutorialMarks + assignmentMarks + testMarks + projectMarks + finalExamMarks;
                        System.out.println("Your ID is: " + id);
                        
                        int marksTotal= (int) Math.round(totalMarks);
                        System.out.printf("Your total marks is %d%%\n", marksTotal);
                        
                        if(marksTotal < 100 && marksTotal >= 80) {
                            System.out.println("Your grade is A");
                    }
                        else if (marksTotal >= 70) {
                            System.out.println("Your grade is B+");
                    }
                        else if (marksTotal >= 65) {
                            System.out.println("Your grade is B");  
                    }
                        else if (marksTotal >= 55) {
                            System.out.println("Your grade is C+");  
                    }
                        else if (marksTotal >= 50) {
                            System.out.println("Your grade is C");  
                    }
                        else if (marksTotal >= 40) {
                            System.out.println("Your grade is D");  
                    }
                        else if (marksTotal >= 0) {
                            System.out.println("Your grade is F");  
                    }
                        else {
                            System.out.println("Invalid grade!");
                    }
                        
                        if (marksTotal > 77) {
                            int gradeA = A - marksTotal;
                            if (gradeA == 1){
                                System.out.printf("Total marks: %.1f. After round up is %d. %d-%d is %d mark. Borderline\n",totalMarks,marksTotal,A,marksTotal,gradeA);
                            }
                            
                            else if (gradeA != 1 && gradeA != 0){
                                System.out.printf("Total marks: %.1f. After round up is %d. %d-%d is %d mark. Not borderline\n",totalMarks,marksTotal,A,marksTotal,gradeA);
                            }
                            
                            else {
                                System.out.printf("Total marks: %.1f. After round up is %d. %d-%d is %d mark.\n",totalMarks,marksTotal,A,marksTotal,gradeA);
                            }
                            
                        }
                        
                        else if (marksTotal > 67) {
                            int gradeBPlus = bPlus - marksTotal;
                            if (gradeBPlus == 1){
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + bPlus + "-" + marksTotal + " is " + gradeBPlus + " mark. Borderline");
                            }
                            
                            else if (gradeBPlus != 1 && gradeBPlus != 0){
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + bPlus + "-" + marksTotal + " is " + gradeBPlus + " mark. Not borderline");
                            }
                            
                            else {
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + bPlus + "-" + marksTotal + " is " + gradeBPlus + " mark.");
                            }
                        }
                        
                        else if (marksTotal > 62) {
                            int gradeB = B - marksTotal;
                            if (gradeB == 1){
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + B + "-" + marksTotal + " is " + gradeB + " mark. Borderline");
                            }
                            
                            else if (gradeB != 1 && gradeB != 0){
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + B + "-" + marksTotal + " is " + gradeB + " mark. Not borderline");
                            }
                            
                            else {
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + B + "-" + marksTotal + " is " + gradeB + " mark.");
                            }
                        }
                        
                        else if (marksTotal > 52) {
                            int gradeCPlus = cPlus - marksTotal;
                            if (gradeCPlus == 1){
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + cPlus + "-" + marksTotal + " is " + gradeCPlus + " mark. Borderline");
                            }
                            
                            else if (gradeCPlus != 1 && gradeCPlus != 0){
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + cPlus + "-" + marksTotal + " is " + gradeCPlus + " mark. Not borderline");
                            }
                            
                            else {
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + cPlus + "-" + marksTotal + " is " + gradeCPlus + " mark.");
                            }
                        }  
                        
                        else if (marksTotal > 47) {
                            int gradeC = C - marksTotal;
                            if (gradeC == 1){
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + C + "-" + marksTotal + " is " + gradeC + " mark. Borderline");
                            }
                            
                            else if (gradeC != 1 && gradeC != 0){
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + C + "-" + marksTotal + " is " + gradeC + " mark. Not borderline");
                            }
                            
                            else {
                                System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + C + "-" + marksTotal + " is " + gradeC + " mark.");
                            }
                        }
                        
                        else if (marksTotal > 37) {
                           int gradeD = D - marksTotal;
                           if (gradeD == 1){
                               System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + D + "-" + marksTotal + " is " + gradeD + " mark. Borderline");
                           }
                            
                           else if (gradeD != 1 && gradeD != 0){
                               System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + D + "-" + marksTotal + " is " + gradeD + " mark. Not borderline");
                           }
                            
                           else {
                               System.out.println("Total marks: " + totalMarks + ". After round up is " + marksTotal + ". " + D + "-" + marksTotal + " is " + gradeD + " mark.");
                           }
                        }    
                        
                        else {
                            System.out.print("Invalid total marks!");
                        }
                        
                    }
                    
                   }while(finalExam > 100 || finalExam < 0);
                        
                 }
                    
                   }while(project > 100 || project < 0);
                        
                 }
                    
                   }while(test > 100 || test < 0);
                        
                 }
                    
                   }while(assignment > 100 || assignment < 0);
                    
                }
                    
            }while(tutorial > 100 || tutorial < 0);
                
         }
                 
        }while(id.isEmpty()); 
                            
                    System.out.println("Would you like to enter another student's mark? [Y/N]");
                    reenter = input.next();
                    enter = reenter.toLowerCase();                               
        
        while(!"Y".equals(enter) || !"N".equals(enter)) {
            
            System.out.println("Invalid input. Please enter again!\nWould you like to enter another student's mark? [Y/N]");
            reenterAgain = input.next();
            enterAgain = reenterAgain.toLowerCase(); 
        }
        
        }while(enterAgain.equalsIgnoreCase("Y"));

    }//end main
}//end class

enter=reenter.toLowerCase()你不是说
toUpperCase()?并且您永远不会使用
enterreach=reenterAgain.toUpperCase()退出
-循环测试
输入
,而不是
再次输入
。(您需要学习方法和许多其他基本知识,因为代码极其冗长和重复。)
   System.out.println("Would you like to enter another student's mark? [Y/N]");
                    reenter = input.next();
                    enter = reenter.toLowerCase();                               
        
        while(!"Y".equals(enter) || !"N".equals(enter)) {
            
            System.out.println("Invalid input. Please enter again!\nWould you like to enter another student's mark? [Y/N]");
            reenterAgain = input.next();
            enterAgain = reenterAgain.toLowerCase(); 
        }