Pipeline SC = new pipeline (system. In );
Int conditon2 = SC. nextint ();
Switch (conditon2 ){
Case 1:
For (INT I = 0; I <theory. length; I ++ ){
If (theory [I] = NULL ){
System. Out. Print ("Enter the course number :");
Courseid = SC. nextline ();
System. Out. Print ("Enter the Course name :");
Coursename = SC. nextline ();
Break;
}
Break;
Default:
Break;
}
}
Why, when the program is running, enter 1, press enter,
Enter the course number. Enter the course name:
You use SC. when nextint () is used to read an int, if it is input on a row and then press enter to end, the cursor will not skip the '\ n' at the end, while the nextline () the function is to skip '\ n' and return the skipped string, so your next call to nextline () is because there is already a' \ n' in the buffer zone ', so I jumped to the input course name.
The solution is to add nextline () after nextint ():
Pipeline SC = new pipeline (system. In );
Int conditon2 = SC. nextint ();SC. nextline (); // skip '\ N'
Switch (conditon2 ){
Case 1:
For (INT I = 0; I <theory. length; I ++ ){
If (theory [I] = NULL ){
System. Out. Print ("Enter the course number :");
Courseid = SC. nextline ();
System. Out. Print ("Enter the Course name :");
Coursename = SC. nextline ();
Break;
}
Break;
Default:
Break;
}
}