1. 程式人生 > >第二次課中的一些問題

第二次課中的一些問題

ati num img ges dia mat integer sage val

技術分享

源程序代碼:

// 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 <= 1000; i++ ) {
value = 1 + (int) ( Math.random() * 6);
output += value + " ";

if ( i % 5 == 0 )
output += "\n";
}

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

System.exit( 0 );
}
}

程序結果截圖:

技術分享

技術分享

輸出後換行,比如:
System.out.println("a");
System.out.println("b");
結果:
a
b

第二次課中的一些問題