小编San*_*non的帖子

if else语句不能正常工作

这是我第一次使用这个论坛而且我对整个Java体验都不熟悉,所以如果这是一个非常简单的修复,请原谅我.

我正在尝试为学校制作这个项目,但是我无法让我的if else声明工作.正如你所看到的,如果你进入近战或远程,一切都没问题,但如果不这样做,它会重定向你.我的问题是,即使你键入近战或远程,它将首先引导你到if方法,然后它会立即将你重定向到else语句.

有谁知道我怎么解决这个问题?

newchamp.Type = JOptionPane.showInputDialog(null, "What type of champion have you summoned? (melee or ranged)", "Type", JOptionPane.PLAIN_MESSAGE);
        if (Type.equalsIgnoreCase("melee")) {
           JOptionPane.showMessageDialog(null,"You have now confirmed your champion, you can not edit anything from this point on.");
        }
        if (Type.equalsIgnoreCase("ranged")) {
              JOptionPane.showMessageDialog(null,"You have now confirmed your champion, you can not edit anything from this point on.");
        }
        else {
            JOptionPane.showMessageDialog(null,"You can only choose Melee or Ranged!");
            newchamp.Type = JOptionPane.showInputDialog(null, "What type of champion have you summoned? (Melee or Ranged)", "Type", …
Run Code Online (Sandbox Code Playgroud)

java if-statement

-1
推荐指数
2
解决办法
2304
查看次数

标签 统计

if-statement ×1

java ×1