我需要帮助修复一个java bug
所以我正在做一个文字游戏,我有一个错误弹出。简而言之,当我运行程序时,它会这样做我需要帮助修复一个java bug,java,Java,所以我正在做一个文字游戏,我有一个错误弹出。简而言之,当我运行程序时,它会这样做 Channel name: hey Your channel name, hey, are you sure you like this name? type yes or no. no Name for video? 我想发生的是,当有人说“不”时,它会重新启动程序,但程序仍在继续。这是密码 public static void main(String[] arg
Channel name:
hey
Your channel name, hey, are you sure you like this name? type yes or no.
no
Name for video?
我想发生的是,当有人说“不”时,它会重新启动程序,但程序仍在继续。这是密码
public static void main(String[] args) {
//views
//channel name
String cfc = "Channel name: ";
System.out.println(cfc);
String cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
@SuppressWarnings("unused")
Boolean nn;
String yn;
while (true) {
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
break;
} else if (yn.equals("no")) {
nn = false;
break;
} else {
System.out.println("Channel name: ");
System.out.println(cfc);
String un = sc.nextLine();
System.out.println("Your channel name, " + un + ", are you sure you like this name? type yes or no.");
}
}
Video();
}
我不知道有什么问题。请帮忙。我相信你只需要
继续
而不是中断我相信你只需要继续
而不是中断我相信你只需要继续
而不是中断我相信你只需要继续
而不是break
break
会打断您的循环,因此当您输入no
时,您会跳出循环,并在视频
方法中运行
相反,不要偷懒,在循环中使用实际的退出条件。另外,您希望至少运行一次此循环,因此请改为执行while
循环,这将确保循环必须至少运行一次
此外,您还需要将提示移动到循环中,以便重复提示,否则可能对用户没有意义,例如
boolean nn = false;
String cfc = "Channel name: ";
String cn = null;
do {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
}
} while (!nn);
break
正在中断循环,因此当您输入no
时,您正在中断循环并在视频
方法中运行
相反,不要偷懒,在循环中使用实际的退出条件。另外,您希望至少运行一次此循环,因此请改为执行while
循环,这将确保循环必须至少运行一次
此外,您还需要将提示移动到循环中,以便重复提示,否则可能对用户没有意义,例如
boolean nn = false;
String cfc = "Channel name: ";
String cn = null;
do {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
}
} while (!nn);
break
正在中断循环,因此当您输入no
时,您正在中断循环并在视频
方法中运行
相反,不要偷懒,在循环中使用实际的退出条件。另外,您希望至少运行一次此循环,因此请改为执行while
循环,这将确保循环必须至少运行一次
此外,您还需要将提示移动到循环中,以便重复提示,否则可能对用户没有意义,例如
boolean nn = false;
String cfc = "Channel name: ";
String cn = null;
do {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
}
} while (!nn);
break
正在中断循环,因此当您输入no
时,您正在中断循环并在视频
方法中运行
相反,不要偷懒,在循环中使用实际的退出条件。另外,您希望至少运行一次此循环,因此请改为执行while循环,这将确保循环必须至少运行一次
此外,您还需要将提示移动到循环中,以便重复提示,否则可能对用户没有意义,例如
boolean nn = false;
String cfc = "Channel name: ";
String cn = null;
do {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
}
} while (!nn);
这里有一些多余的代码片段,我认为您可以这样做:
String cfc = "Channel name: ";
String cn;
boolean nn = false;
String yn;
while (!nn) {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
} else {
nn = false;
}
}
显然你以前没有使用过
nn
,这很奇怪。我相信你已经申报使用了,对吗?还有一对,如果其他的足以实现你想要的。有一些多余的代码片段,我想你可以这样做:
String cfc = "Channel name: ";
String cn;
boolean nn = false;
String yn;
while (!nn) {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
} else {
nn = false;
}
}
显然你以前没有使用过nn
,这很奇怪。我相信你已经申报使用了,对吗?还有一对,如果其他的足以实现你想要的。有一些多余的代码片段,我想你可以这样做:
String cfc = "Channel name: ";
String cn;
boolean nn = false;
String yn;
while (!nn) {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
} else {
nn = false;
}
}
显然你以前没有使用过nn
,这很奇怪。我相信你已经申报使用了,对吗?还有一对,如果其他的足以实现你想要的。有一些多余的代码片段,我想你可以这样做:
String cfc = "Channel name: ";
String cn;
boolean nn = false;
String yn;
while (!nn) {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
} else {
nn = false;
}
}
显然你以前没有使用过nn
,这很奇怪。我相信你已经申报使用了,对吗?如果还有一对,
就足以实现您想要的功能。使用do while循环会更好。
此外,下面代码中的elseif和else部分可能是多余的
boolean nn = false;
String cfc = "Channel name: ";
String cn = null;
do {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
} else if (yn.equals("no")) {
System.out.println("Channel name: "); // Possibly duplicated?
} else {
//Handle cases that yn not equals to "yes" or "no"
}
} while (!nn);
使用do-while循环会更好。
此外,下面代码中的elseif和else部分可能是多余的
boolean nn = false;
String cfc = "Channel name: ";
String cn = null;
do {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
} else if (yn.equals("no")) {
System.out.println("Channel name: "); // Possibly duplicated?
} else {
//Handle cases that yn not equals to "yes" or "no"
}
} while (!nn);
使用do-while循环会更好。
此外,下面代码中的elseif和else部分可能是多余的
boolean nn = false;
String cfc = "Channel name: ";
String cn = null;
do {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
} else if (yn.equals("no")) {
System.out.println("Channel name: "); // Possibly duplicated?
} else {
//Handle cases that yn not equals to "yes" or "no"
}
} while (!nn);
使用do-while循环会更好。
此外,下面代码中的elseif和else部分可能是多余的
boolean nn = false;
String cfc = "Channel name: ";
String cn = null;
do {
System.out.println(cfc);
cn = sc.nextLine();
System.out.println("Your channel name, " + cn + ", are you sure you like this name? type yes or no.");
yn = sc.nextLine().trim().toLowerCase();
if (yn.equals("yes")) {
nn = true;
} else if (yn.equals("no")) {
System.out.println("Channel name: "); // Possibly duplicated?
} else {
//Handle cases that yn not equals to "yes" or "no"
}
} while (!nn);
你写道:“当有人说不,它重新启动程序”——你的意思是:“退出程序”?<代码>破解< /代码>正在跳出循环…考虑使用一个实际的“真正”退出原因到你的循环……我希望它重置,这样它会重复开头行“通道名:”然后你输入你的名字将是什么。“当有人说不,它重新启动程序”——你的意思是:“退出程序”?<代码>破解< /代码>正在跳出循环…考虑使用一个实际的“实际”退出原因到你的循环……我希望它重置,这样它会重复开头行“通道名:”然后你输入你的名字将是什么。当有人说“否”时,它会重新启动程序“-你是说:”退出程序“?<代码>破解<代码>正在循环中……考虑使用一个实际的“实际”退出原因到你的循环……我希望它重置,这样它会重复开头行“通道名:”然后你输入你的名字将是什么。当有人说“否”时,它会重新启动程序“-你是说:”退出程序“?<代码>破解< /代码>正在跳出循环…考虑使用一个实际的“实际”退出原因到你的循环…我希望它重置,这样它会重复开头行“频道名称:“那么你输入你的名字。我会检查一下,看这是否有效。再说一次,我只是一个初学者。开始吧…看一看更多的细节。我认为你的代码是多余的,我可以说它是错误的。。如果你键入“否”,会发生什么?我想你的回答有点苛刻。有一行额外的代码不支持n