为什么赢得NetBeans上此程序显示中的最后一个输出行?

时间:2017-09-16 19:02:38

标签: java netbeans

我试图制作一个简单的商店"程序提示退出程序结束。如果用户输入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.");
           }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

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.");
         }
        }
       }
       }