randomint.java

来自「金旭亮的java教案」· Java 代码 · 共 25 行

JAVA
25
字号
// RandomInt.java
// Shifted, scaled random integers
import javax.swing.JOptionPane;

public class RandomInt {
   public static void main( String args[] )
   {
      int value;
      String output = "";

      for ( int i = 1; i <= 20; i++ ) {
         value = 1 + (int) ( Math.random() * 6 );
         output += value + "  ";
         
         if ( i % 5 == 0 )
            output += "\n";
      }

      JOptionPane.showMessageDialog( null, output,
         "20 Random Numbers from 1 to 6",
         JOptionPane.INFORMATION_MESSAGE );

      System.exit( 0 );
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?