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: , , ,

This entry was posted on 星期一, 四月 13th, 2015 at 10:05:03 and is filed under 103(下)程式設計(二). You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment