Posts Tagged ‘104(下)’

13
四月

程式設計二程式 04/13: ex5

   Posted by: admin    in 103(下)程式設計(二)

import java.io.*;
public class Ex5Class {
	public static void main(String[] args) {
		//建立亂數的物件
		Random rnd = new Random();
		try
		{
			FileWriter writer = new FileWriter("arrival.txt");
			PrintWriter pw = new PrintWriter(writer);
			//產生1000個亂數
			for (int i=0  i<1000  i++)
			{
				int time = rnd.nextInt();////產生1個亂數
				if (time  0) time=-time;
				time = time %30 + 1 
				System.out.printf( %2d\n , time) 
				pw.printf("%2d", time);pw.println();
			 } 
			pw.close();
		}
		catch(FileNotFoundException fe)
	    {
	         System.out.printf(fe.getMessage());
	    }
	    catch(IOException ie)
	    {
	         System.out.printf(ie.getMessage());
	    }
	}
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,