返回列表 發帖
本帖最後由 陳泓瑜 於 2018-4-21 10:52 編輯
  1. public class RANDOM
  2. {

  3.         public static void main(String[] args)
  4.         {
  5.                
  6.                 int j[]=new int[12];
  7.                 for(int i=0;i<12;i++)
  8.                 {
  9.                         j[i]=(int)(Math.random()*12);
  10.                         for(int k=0; k<i; k++)
  11.                         {
  12.                                 if(j[i]==j[k])
  13.                                 {
  14.                                         i--;
  15.                                         break;
  16.                                 }       
  17.                         }
  18.                        
  19.                 }
  20.        
  21.                
  22.                
  23.                 for(int m=0; m<=11; m++)
  24.                 {
  25.                         System.out.println(j[m]);
  26.                 }
  27.         }

  28. }
複製代碼
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3. import java.awt.Image;

  4. import javax.swing.ImageIcon;
  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.border.EmptyBorder;
  8. import javax.swing.JLabel;


  9. public class FLIP extends JFrame {

  10.         private JPanel contentPane;

  11.         /**
  12.          * Launch the application.
  13.          */
  14.         public static void main(String[] args) {
  15.                 EventQueue.invokeLater(new Runnable() {
  16.                         public void run() {
  17.                                 try {
  18.                                         FLIP frame = new FLIP();
  19.                                         frame.setVisible(true);
  20.                                 } catch (Exception e) {
  21.                                         e.printStackTrace();
  22.                                 }
  23.                         }
  24.                 });
  25.         }

  26.         /**
  27.          * Create the frame.
  28.          */
  29.         public FLIP() {
  30.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31.                 setBounds(100, 100, 572, 466);
  32.                 contentPane = new JPanel();
  33.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  34.                 setContentPane(contentPane);
  35.                 contentPane.setLayout(null);
  36.                
  37.                 JLabel C1 = new JLabel("");
  38.                 C1.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  39.                 C1.setBounds(10, 10, 128, 128);
  40.                 contentPane.add(C1);
  41.                
  42.                 JLabel C2 = new JLabel("");
  43.                 C2.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  44.                 C2.setBounds(148, 10, 128, 128);
  45.                 contentPane.add(C2);
  46.                
  47.                 JLabel C3 = new JLabel("");
  48.                 C3.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  49.                 C3.setBounds(286, 10, 128, 128);
  50.                 contentPane.add(C3);
  51.                
  52.                 JLabel C4 = new JLabel("");
  53.                 C4.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  54.                 C4.setBounds(424, 10, 128, 128);
  55.                 contentPane.add(C4);
  56.                 //----------------------
  57.                 JLabel C5 = new JLabel("");
  58.                 C5.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  59.                 C5.setBounds(10, 148, 128, 128);
  60.                 contentPane.add(C5);
  61.                
  62.                 JLabel C6 = new JLabel("");
  63.                 C6.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  64.                 C6.setBounds(148, 148, 128, 128);
  65.                 contentPane.add(C6);
  66.                
  67.                 JLabel C7 = new JLabel("");
  68.                 C7.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  69.                 C7.setBounds(286, 148, 128, 128);
  70.                 contentPane.add(C7);
  71.                
  72.                 JLabel C8 = new JLabel("");
  73.                 C8.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  74.                 C8.setBounds(424, 148, 128, 128);
  75.                 contentPane.add(C8);
  76.                 //----------------------
  77.                 JLabel C9 = new JLabel("");
  78.                 C9.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  79.                 C9.setBounds(10, 286, 128, 128);
  80.                 contentPane.add(C9);
  81.                
  82.                 JLabel C10 = new JLabel("");
  83.                 C10.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  84.                 C10.setBounds(148, 286, 128, 128);
  85.                 contentPane.add(C10);
  86.                
  87.                 JLabel C11 = new JLabel("");
  88.                 C11.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  89.                 C11.setBounds(286, 286, 128, 128);
  90.                 contentPane.add(C11);
  91.                
  92.                 JLabel C12 = new JLabel("");
  93.                 C12.setIcon(new ImageIcon("C:\\Users\\student\\Downloads\\pic\\pic\\0.png"));
  94.                 C12.setBounds(424, 286, 128, 128);
  95.                 contentPane.add(C12);
  96.         }

  97. }
複製代碼

TOP

返回列表