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

0522Prog

Java的數數

Java的數數

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

0515Prog

 

 

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

23
五月

程式設計二上課 05/08: Java的語法

   Posted by: admin Tags: , ,

0508Prog

 

 

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark