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

This entry was posted on 星期一, 三月 30th, 2015 at 10:18:16 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