谁有人机猜拳的代码啊??跪求啦! 我现在不是太懂random函数的应用,向学下,就设计了个猜拳的代码,一直错,谁有代码借鉴下,谢谢了!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你 一个思路public math2(){n=0;} public void setn() { double x; x=Math.random();//生成随机数 x=x*10; n=Math.round(x); n=n%3;} public String caiquan() { if(n==0)return("锤子"); else if(n==1)return("剪刀"); else return("布"); } public static void main(String [] args) { math2 m=new math2(); String str=new String(); m.setn(); str=m.caiquan(); System.out.println(str); }} int random=(int)(int.Math.random()*10%3+1); class ScissorStoneFrabric extends JFrame{ private static final int SCISSOR = 0; private static final int STONE = 1; private static final int FRABRIC = 2; private JButton scissorButton = new JButton("Scissor"); private JButton stoneButton = new JButton("Stone"); private JButton frabricButton = new JButton("不!"); private JTextArea memo = new JTextArea(); public ScissorStoneFrabric() { init(); } private void init() { setLayout(null); setVisible(true); setSize(260, 330); Container cp = getContentPane(); scissorButton.setVisible(true); stoneButton.setVisible(true); frabricButton.setVisible(true); scissorButton.setSize(80, 20); stoneButton.setSize(80, 20); frabricButton.setSize(80, 20); scissorButton.setLocation(5,5); stoneButton.setLocation(90, 5); frabricButton.setLocation(175,5); JScrollPane sp = new JScrollPane(memo, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); sp.setVisible(true); sp.setSize(260, 300); memo.setSize(260, 300); sp.setLocation(0, 30); scissorButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int userVal = -1; if (ae.getSource() == scissorButton) userVal = 0; if (ae.getSource() == stoneButton) userVal = 1; if (ae.getSource() == frabricButton) userVal = 2;// JOptionPane.showMessageDialog(ScissorStoneFrabric.this, ""+userVal); int comVal = ((int)(Math.random() * 1000)) % 3 ; if ((userVal == comVal)) memo.append("Draw game!"); else if (userVal == ((comVal + 1) % 3)) memo.append("You win!"); else memo.append("You cheap!!!!!!!"); memo.append("\n"); } }); stoneButton.addActionListener(scissorButton.getActionListeners()[0]); frabricButton.addActionListener(scissorButton.getActionListeners()[0]); cp.add(scissorButton); cp.add(stoneButton); cp.add(frabricButton); cp.add(sp); }}花了小小時間幫你寫好了,自己把包加好 還有自己加上EXIT_ON_CLOSE,有分就給我,我缺分用 求大神帮忙啊啊啊啊!!!~~ 关于继承中子类对象赋值给父类 数组初始化列表最后可选逗号,此特性使维护长列表变得更容易? 动态数组实现stack的问题 请教大虾(String...)String后面跟三个点是什么意思 jsf问题:如何在panelGrid中合并几个单元呢? 关闭窗口的脚本? JAVA中的输入整数用什么函数? 创建“有理数”类,如何重载“+”“-”“*”“/”四个方法 求救二度梅开 下午没事,初学者写了一个操作数据库的类,直接获取记录集,通过设置参数以及调用存储过程等例子,适合初学者~ java 怎么调用 vf数据库文件
public math2(){n=0;}
public void setn()
{
double x;
x=Math.random();//生成随机数
x=x*10;
n=Math.round(x);
n=n%3;
}
public String caiquan()
{
if(n==0)return("锤子");
else if(n==1)return("剪刀");
else return("布");
}
public static void main(String [] args)
{
math2 m=new math2();
String str=new String();
m.setn();
str=m.caiquan();
System.out.println(str); }}
private static final int SCISSOR = 0;
private static final int STONE = 1;
private static final int FRABRIC = 2;
private JButton scissorButton = new JButton("Scissor");
private JButton stoneButton = new JButton("Stone");
private JButton frabricButton = new JButton("不!");
private JTextArea memo = new JTextArea();
public ScissorStoneFrabric() {
init();
}
private void init() {
setLayout(null);
setVisible(true);
setSize(260, 330);
Container cp = getContentPane();
scissorButton.setVisible(true);
stoneButton.setVisible(true);
frabricButton.setVisible(true);
scissorButton.setSize(80, 20);
stoneButton.setSize(80, 20);
frabricButton.setSize(80, 20);
scissorButton.setLocation(5,5);
stoneButton.setLocation(90, 5);
frabricButton.setLocation(175,5);
JScrollPane sp = new JScrollPane(memo,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
sp.setVisible(true);
sp.setSize(260, 300);
memo.setSize(260, 300);
sp.setLocation(0, 30);
scissorButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int userVal = -1;
if (ae.getSource() == scissorButton) userVal = 0;
if (ae.getSource() == stoneButton) userVal = 1;
if (ae.getSource() == frabricButton) userVal = 2;
// JOptionPane.showMessageDialog(ScissorStoneFrabric.this, ""+userVal);
int comVal = ((int)(Math.random() * 1000)) % 3 ;
if ((userVal == comVal))
memo.append("Draw game!");
else
if (userVal == ((comVal + 1) % 3))
memo.append("You win!");
else
memo.append("You cheap!!!!!!!");
memo.append("\n");
}
});
stoneButton.addActionListener(scissorButton.getActionListeners()[0]);
frabricButton.addActionListener(scissorButton.getActionListeners()[0]);
cp.add(scissorButton);
cp.add(stoneButton);
cp.add(frabricButton);
cp.add(sp);
}
}
花了小小時間幫你寫好了,自己把包加好