怎样将 math.random()型转换为 整型(int)

9742wsx 2002-04-11 03:38:47
怎样将 math.random()double 型转换为 整型(int)
...全文
212 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kkhui 2002-04-11
  • 打赏
  • 举报
回复
直接强制转换
MagicFan 2002-04-11
  • 打赏
  • 举报
回复
如果a是由math.random()得出的double型的数,则
int b = a.intValue();
Times2001 2002-04-11
  • 打赏
  • 举报
回复
先将double转成Double
再用intValue()函数就可以了
hotenM 2002-04-11
  • 打赏
  • 举报
回复
int int1 = (int)(java.lang.Math.random());
给分吧
//变量,表示难度等级为:简单 public static final int EASY = 1; //变量,表示难度等级为:普通 public static final int NATURAL = 2; //变量,表示难度等级为:难 public static final int HARD = 3; //设定初始难度等级为简单 private int grade = Spider.EASY; private Container pane = null; //生成纸牌数组 private PKCard cards[] = new PKCard[104]; private JLabel clickLabel = null; private int c = 0; private int n = 0; private int a = 0; private int finish = 0; Hashtable table = null; private JLabel groundLabel[] = null; public static void main(String[] args){ Spider spider = new Spider(); spider.setVisible(true); } /** **构造函数 */ public Spider(){ setTitle("蜘蛛牌"); setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); //设置框架的大小 setSize(1024, 742); //生成SpiderMenuBar对象,并放置在框架之上 setJMenuBar(new SpiderMenuBar(this)); pane = this.getContentPane(); //设置背景颜色 pane.setBackground(new Color(0, 112, 26)); //将布局管理器设置成为null pane.setLayout(null); clickLabel = new JLabel(); clickLabel.setBounds(883, 606, 121, 96); pane.add(clickLabel); clickLabel.addMouseListener(new MouseAdapter(){ public void mouseReleased(MouseEvent me){ if (c < 60){ Spider.this.deal(); } } }); this.initCards(); this.randomCards(); this.setCardsLocation(); groundLabel = new JLabel[10]; int x = 20; for (int i = 0; i < 10; i++) { groundLabel[i] = new JLabel(); groundLabel[i] .setBorder(javax.swing.BorderFactory .createEtchedBorder(javax.swing.border.EtchedBorder.RAISED)); groundLabel[i].setBounds(x, 25, 71, 96); x += 101; this.pane.add(groundLabel[i]); } this.setVisible(true); this.deal(); this.addKeyListener(new KeyAdapter(){

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧