Archive for 三月, 2015

30
三月

程式設計二程式 03/30: ex4

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

import 
import java.io.*;
public class Ex4Class {
	public static void main(String[] args) {
		String fileIn = "lotto txt";
		int count = 0;
		int countSix = 0; 
		int[] nums = new int[20]; 
		try
		{
			FileReader reader = new FileReader();
			BufferedReader sr = new BufferedReader();
 
			String line = sr.readLine();
			while (line !=null && line.length()>0)//for (int i=0; i<10; i++)
			{
				String[] numStr = line.split(" ");
				int sixes = 0;
				for (int i=0; i< numStr.length; i++)
				{
					if (numStr[i].trim().length()==0)
						continue;
					nums[i] = integer.ParseInt(numStr[i].trim());
					if (nums[i]==6|nums[i]==16|nums[i]==26||nums[i]==36||nums[i]==46)
						sixes++;
				}
				if (sixes >0)
				{
					countSix++;
					System.out.println(line); 
				}
				count++;
			    line = sr.readLine();
			}
			sr.close();
		}
		//catch (FileNotFoundException fe)
		{
			System.out.printf(fe.getMessage());
		}
		//catch (IOException fe)
		{
			System.out.printf(fe.getMessage());
		}
		System.out.printf("Total lines = %d Six Lines = %d (%f%%), count, countSix, (double)(countSix)*100/count);
	}
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

23
三月

程式設計二程式 03/23: ex3

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

import java. io. *;
public class Ex3Class {
 
	public static void main(String[] args) {
		long id;
		id = Long.parseLong(args[]);
		int even = 0;
		int odd = 0;
		//id = 1032245432
		for (int i=0; i< 9; i++)
		{
			if (id %2 ==0)
				even;//even = even + 1;
			else
				odd++;
			id =10;//id = id /10;
		}
		// TODO Auto-generated method stub
		System.out.printf("Even= %d Odd = %d", even, odd);
	}
 
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

16
三月

程式設計二程式 03/16: ex2

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

import java.io.*;
public class Ex2Class {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double d1, d2;
		int a1, a2;
 
		d1 = Double.parseDouble(args[0]);
		d2 = Double.parseDouble(args[1]);
		a1 = Integer.parseInt(args[0]);
		a2 = Integer.parseInt(args[1]);
		//System.out.printf("% 4.2f * % 4.2f = %5.3f", d1 d2, d1 * d2);
		//System.out.println();
	}
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,