所以我有我的程序,它只是在最后一个问题(需要输入)之后不会运行。我的代码在这里:
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();
关于java - 运行程序并输入正确的输入后,程序不会显示程序的答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30576773/