如您所见,这是一个简单的 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");
}