Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么赢了';该程序的最后一行输出是否显示在NetBeans上?_Java_Netbeans - Fatal编程技术网

Java 为什么赢了';该程序的最后一行输出是否显示在NetBeans上?

Java 为什么赢了';该程序的最后一行输出是否显示在NetBeans上?,java,netbeans,Java,Netbeans,我正在尝试制作一个简单的“存储”程序,并在最后提示退出该程序。如果用户键入yes,它将退出。但如果他们说不,应该只打印一条消息,让他们知道他们可以继续购物。但由于某种原因,该消息并未出现。这是物体 public class HelloShopper1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.o

我正在尝试制作一个简单的“存储”程序,并在最后提示退出该程序。如果用户键入yes,它将退出。但如果他们说不,应该只打印一条消息,让他们知道他们可以继续购物。但由于某种原因,该消息并未出现。这是物体

public class HelloShopper1 {
   public static void main(String[] args) {
              Scanner scanner = new Scanner(System.in);
              System.out.print("Hello Shopper, what is your name?\n");
              String input = scanner.nextLine();
              if(!input.matches("[a-zA-Z_]+")) {
              System.out.println("Nice try " + input + " . Get out of my store!");
              } else {
             System.out.println("Thank you, " + input + ". It is my pleasure to help you today.");
             System.out.println("Do you want to close this program?");
             String input1 = scanner.nextLine();
             System.out.println(input1);
             if(input1 == "yes") {
             System.exit(0);
             if(input1 == "no") {
             System.out.println("Thank god. Please continue shopping.");
           }
        }
    }
}

不要使用
==
来比较字符串。使用
.equals(…)
.equalsIgnoreCase(…)
方法。了解
==
检查引用相等,而方法则执行您真正感兴趣的测试:函数相等。
import java.util.*;
public class HelloShopper1 
{
public static void main(String[] args) 
{
          Scanner scanner = new Scanner(System.in);
          System.out.print("Hello Shopper, what is your name?\n");
          String input = scanner.nextLine();
          if(!input.matches("[a-zA-Z_]+")) 
          {
          System.out.println("Nice try " + input + " . Get out of my 
       store!");
          }else{
         System.out.println("Thank you, " + input + ". It is my pleasure to 
         help you today.");
         System.out.println("Do you want to close this program?");
         String input1 = scanner.nextLine();
         if(input1.equalsIgnoreCase("yes")) 
         {
         System.exit(0);
         }
         if(input1.equalsIgnoreCase("no")) 
         {
         System.out.println("Thank god. Please continue shopping.");
         }
        }
       }
       }