用户输入跳过 if 语句

时间:2021-07-06 05:26:03

标签: java string

如您所见,这是一个简单的 Java 程序,我询问用户他们参加的课程数量,然后按百分比告诉他他们是否可以参加考试,但是当我尝试在 if 语句中输入时,该行跳过了但是代码运行无误

Scanner s = new Scanner(System.in);
    
    int   totalclass = 125 ;

    System.out.println("enter total Number of classes you Attend : ");

 float   attend = s.nextInt();

 float percentage = (attend/125 *100);

 if (percentage < 75){

 System.out.println("do have any medical cause Enter  yes(y) or no(n) : ");

为什么这条线不工作,我想给输入(字符串)

     String  str = s.nextLine();

但是这个跳过了

     if(str.equalsIgnoreCase("y") ){

         System.out.println("Submited medical letter so we consider You to sit in Exam");

     }else{

         System.out.println("Your attendence is " + percentage + "% which is less then 75% ,you are not eligible for sit in Exam");

     }
 }else {
     System.out.println("You can sit in exam");
 }

0 个答案:

没有答案
相关问题