Java 如何编写一个';s应该是布尔值,但使用JOptionPane,答案可以是整数?

Java 如何编写一个';s应该是布尔值,但使用JOptionPane,答案可以是整数?,java,while-loop,joptionpane,Java,While Loop,Joptionpane,如何编写一个假定为布尔值的循环,而使用JOptionPane可以得到一个整数 布尔提示菜单(int菜单) 这将代表代码的核心 应该位于main()内的循环体中 如果它应该继续运行,则返回true 如果要退出,则返回false 请注意,promptMenu接受一个int参数: 0-打印主菜单 到目前为止,我得到的是: import javax.swing.JOptionPane; public class BankSystem { //Fields static boo

如何编写一个假定为布尔值的循环,而使用
JOptionPane
可以得到一个整数

  • 布尔提示菜单(int菜单)
    • 这将代表代码的核心
    • 应该位于
      main()
      内的循环体中
    • 如果它应该继续运行,则返回true
    • 如果要退出,则返回false
    • 请注意,
      promptMenu
      接受一个
      int
      参数: 0-打印主菜单
到目前为止,我得到的是:

import javax.swing.JOptionPane;

public class BankSystem {

    //Fields
    static boolean question = true;
    static String q ;
    static int qt;

    //Methods
    public static void main(String[]args)
    {
        while(question = true)
        {
            promptMenu (qt) ;
        }
    }

    static int promptMenu( int qt )
    {
        q = JOptionPane.showInputDialog ("Gen's Bank" + "\n \n Print main menu? 0-> YES\n\n") ;
        qt = Integer.parseInt(q);

        if (qt != 0)
        {
            question = false;
        }

        return (qt);
    }

}
如果按任何不是0的键,它仍会循环。任何建议都会有帮助。

你得到了什么:

public static void main(String[]args)
{
    while(question = true)
    {
        promptMenu (qt) ;
    }
}
您需要的:

public static void main(String[]args)
{
    while(question == true)
    {
        promptMenu (qt) ;
    }
}
return true;

return false;

如果要检查条件,必须使用以下参数之一(=,!=,=)。一个=用于为变量赋值。

仔细阅读问题。该问题要求您提供一种方法:

boolean promptMenu( int menu )
您所写的是另一种方法:

int promptMenu( int menu )
讲师希望您编写一个返回
布尔值的方法,但您正在编写一个返回
int
的方法。你没有回答被问到的问题

要返回
布尔值
,您需要:

public static void main(String[]args)
{
    while(question == true)
    {
        promptMenu (qt) ;
    }
}
return true;

return false;
或者类似于:

boolean boolVar;
boolVar = // Your code here.
return boolVar;