Closed. This question needs details or clarity。它当前不接受答案。












想改善这个问题吗?添加详细信息并通过editing this post阐明问题。

6年前关闭。



Improve this question





import java.util.*;
import javax.swing.JOptionPane;
import javax.swing.*;
import java.lang.Math;

public class diceGame {
public static void main(String[] arg) {

  int alydarPace;
  int affirmedPace;

  boolean wantsToPlay = true;

  ImageIcon INPUTPIC = new ImageIcon("INPUTPIC.jpg");

  while(wantsToPlay == true){
  JOptionPane.messageDialog(null,"Welcome to watch the greatest rivalry in horse racing history... Affirmed vs Alydar.", "", 0, INPUTPIC);

   {
   int alydarPace; alydarPace = (int)(Math.random()*6+1);
   int affirmedPace; affirmedPace = (int)(Math.random()*6+1);

  if (alydarPace > affirmedPace) {

  JOptionPane.showMessageDialog(null, "And away they go with Alydar taking the Lead!", "", 0, INPUTPIC);


}否则,如果(alydarPace
 JOptionPane.showMessageDialog(null, "And away they go with Affirmed taking the Lead!", "", 0, INPUTPIC);


} else if(alydarPace = affirmedPace){

 JOptionPane.showMessageDialog(null, "And away they go with both horses evenly running neck and neck!", "", 0, ChildSpainFlag);


}

int alydarPace; alydarPace =(int)(Math.random()* 6 + 1)+ alydarPace;
int affirmedPace; affirmedPace =(int)(Math.random()* 6 + 1)+ affirmedPace;

JOptionPane.showMessageDialog(null,“顺其自然,胜利者是Alydar!”,“”,0,INPUTPIC);

}否则,如果(alydarPace
 JOptionPane.showMessageDialog(null, "Down the stretch they come and the winner is Affirmed!", "", 0, INPUTPIC);


} else if(alydarPace = affirmedPace){

 JOptionPane.showMessageDialog(null, "Down the stretch they come.. is a photo finish and the horses have tied!", "", 0, INPUTPIC);


}

int answer = JOptionPane.showConfirmDialog(null,“您想再次播放吗?”);

if(answer != JOptionPane.YES_OPTION){
  wantsToPlay = false;
} else {
  System.exit(0);
}


}

最佳答案

尽管您的内容有些混乱,但我怀疑您的实际问题是您使用的是赋值运算符(=),而实际上需要比较运算符(==)。

这是Java(以及其他语言)的典型初学者陷阱。单等号表示将变量放在符号的左侧,然后通过评估符号的右侧为其分配值。

a = b + 3


将值b + 3分配给a

双等号表示比较两个值。

a == b + 3


提出问题“ ab多3”。

在Java中if语句的条件内,您需要提出这样的问题(您需要boolean)。您应该从使用错误的错误消息中得到错误消息,例如“无法从int转换为boolean”。

10-07 14:12