这是程序
import java.util.Scanner; //imports class
public class blank2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
boolean valid = true;
String ans;
ans = in.next(); //answer is a string
如果您输入“y”,它会直接转到 else 语句。
while (valid == true)
{
它总是跳过这个语句
if (ans == "y")
{
System.out.println("it works");
valid = false;
{
else
{
System.out.println("no work");
valid = false;
{
}
}
}
它只是行不通