我想做的是,当程序询问您是否要添加另一个学生时,它会说“您要添加另一个学生Y/N
吗?” 如果Y
输入,那么它会让你添加另一个,如果你输入N
它会带你回到我的程序的主菜单。所以我设置Y=1
,N=0
我只是想弄清楚程序如何阅读Y
并知道该怎么做。
public class TestStudent {
public static void main (String[] args) throws IOException
{
InputStreamReader isr = new InputStreamReader (System.in );
BufferedReader stdin = new BufferedReader( isr );
String check, tempString, tempString2, setName, getName, setScore, getScore;
int tempInt, tempInt2, y, n;
boolean quit = false;
y=1;
n=0;
Student s1, s2, s3;
s1 = new Student();
s2 = new Student();
s3 = new Student();
do
{
System.out.println("A - Add student, D - Delete student, F - Find student, H - Help, S - Scores, X - Exit");
check = stdin.readLine().toLowerCase();
switch (check)
{
case "a":
System.out.println("Enter the student's name");
tempString = stdin.readLine();
s1.setName(tempString);
System.out.println("Would you like to add another student Y/N?");
tempString = stdin.readLine();
if (y=1) {
System.out.println("Enter the student's name");
tempString = stdin.readLine();
}
s2.setName(check);
s3.setName(check);
break;