Archive for the ‘舊101課程’ Category

29
五月

程式設計二程式 05/29: TestClassA.java

   Posted by: admin Tags: , , ,

import java.io.*;
import java.util.*;
 
public class TestClassA {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String filename = "record.txt";
		Random rdn = new Random();
		int num=100;
 
 
 
		try
		{
			FileWriter writer = new FileWriter(filename);
			PrintWriter pw = new PrintWriter(writer);
 
 
			for (int i=0; i<10000; i++)
			{
				num = rdn.nextInt()%101;
				if (num <0) num = -num + 100;
				else num = num + 100;
 
				System.out.printf("%d", num);System.out.println();
				pw.printf("%d", num); pw.println();
			}
 
			writer.close();
		}
		catch (FileNotFoundException fe)
		{
			System.out.printf(fe.getMessage());
			return;
		}
		catch (IOException ie)
		{
			System.out.printf(ie.getMessage());
			return;
		}
	}
 
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

29
五月

程式設計二程式 05/29: TestClassB.java

   Posted by: admin Tags: , , ,

import java.io.*;
import java.util.*;
public class TestClassB {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String filename = "record.txt";
 
		try
		{
			FileReader reader = new FileReader(filename);
			BufferedReader br = new BufferedReader(reader);
 
			int count = 0;
			String line = br.readLine();
			while (line!=null && line.length() >0)
			{
				int num = Integer.parseInt(line);
				if (num < 125)
					count ++;
				System.out.printf("%d", num);System.out.println();
				line = br.readLine();
			}
			System.out.printf("<125 #=%d", count);System.out.println();
			reader.close();
		}
		catch (FileNotFoundException fe)
		{
			System.out.printf(fe.getMessage());
			return;
		}
		catch (IOException ie)
		{
			System.out.printf(ie.getMessage());
			return;
		}
	}
 
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark