2011-03-18

2011/03/18

產生介於1-49的7個亂數

礙於時間關係無法慢慢研究如何使用迴圈

用複製七個的做法

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Work3 extends JFrame implements ActionListener {


  public static void main(String[] args) {
 Work3 test = new Work3();
      }
   
Work3()
{
  JFrame tframe=new JFrame("Button Frame");
    JButton button1 = new JButton("Submit");
JButton button2 = new JButton("Submit1");
button1.addActionListener(this);
    getContentPane().add(button1);
    getContentPane().add(button2);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout());
    setSize(200,100);
    setVisible(true);

    //    System.exit(0);
}

public void actionPerformed(ActionEvent e)
{


int r1,r2,r3,r4,r5,r6,r7;
r1=(int) (Math.random()*49)+1;
r2=(int) (Math.random()*49)+1;
r3=(int) (Math.random()*49)+1;
r4=(int) (Math.random()*49)+1;
r5=(int) (Math.random()*49)+1;
r6=(int) (Math.random()*49)+1;
r7=(int) (Math.random()*49)+1;
System.out.println(r1);
System.out.println(r2);
System.out.println(r3);
System.out.println(r4);
System.out.println(r5);
System.out.println(r6);
System.out.println(r7);
}

  }

沒有留言:

張貼留言