在 运行 并输入正确的输入后,程序不会显示程序的答案

Program won't display answer of program after running it and typing in the correct input

所以我有我的程序,只是在最后一个问题(需要输入)之后不会 运行。我的代码在这里:

import java.util.Scanner;

import javax.swing.JOptionPane;

public class HiConor
{

   public static void main(String[] args)
   {

      String result; 
      int selection;
      int Entry;
      boolean isYes;
      System.out.print("Starting Program");
      System.out.print(".");
      System.out.print("");
      System.out.print(".");
      System.out.print("");
      System.out.print(".");
      System.out.print("");
      System.out.print(".");
      JOptionPane.showMessageDialog(null, "Hello there!");
      selection = JOptionPane.showConfirmDialog(null, "Are you doing good?");
      boolean isNo;
      boolean isCancel;
      isNo = (selection == JOptionPane.NO_OPTION);
      isYes = (selection == JOptionPane.YES_OPTION);
      isCancel = (selection == JOptionPane.CANCEL_OPTION);
      if(isYes){
      JOptionPane.showMessageDialog(null, "Yes?" + " That's nice to hear!");
         } 
      if(isNo){
      JOptionPane.showMessageDialog(null, "No?" + " Well then, cheer up!");
         } 
      if(isCancel){
      JOptionPane.showMessageDialog(null, "Fine then, don't respond");
         }   
      Scanner keyBoard = new Scanner(System.in);
      Scanner input = new Scanner(System.in);
      JOptionPane.showInputDialog(null, "What is your name?",
      "Mlg recess poofs",
      JOptionPane.ERROR_MESSAGE);
      String userinput = input.next();
      if(userinput.equals("alex")){
         JOptionPane.showMessageDialog(null, "What a lovely name!");
         }

      JOptionPane.showMessageDialog(null, "I have a feeling you're trolling me " + ". This is the end of the program. Goodbye.");
      }}

改成这样

String userinput =  JOptionPane.showInputDialog(null, "What is your name?",
      "Mlg recess poofs",
      JOptionPane.ERROR_MESSAGE);

删除:

Scanner input = new Scanner(System.in);
String userinput = input.next();

您正在混合输入法。您是想从对话框中获取用户的响应,还是从他们在控制台中输入的内容中获取用户响应 windows?您似乎正在使用 JOptionPane 所以我假设您需要该对话框。在这种情况下,您根本不需要使用 Scanner 对象。对 JOptionPane.showInputDialog 的调用已经返回用户键入的任何内容,但您没有将其保存在任何变量中。只需执行以下操作:

String userinput = JOptionPane.showInputDialog(null, "What is your name?",
    "Mlg recess poofs",
    JOptionPane.ERROR_MESSAGE);

也别费心打电话给 input.next()