import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class TestJava {
private static String[] open={"05","07","09","21","23","24","06"};
public static void main(String[] args) {
String path = "E:\\fangaiwen\\colordouble.txt";
try {
readFile(path);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Java读取文件按行读取
* @param fileName 文件路径
* @throws IOException
*/
public static void readFile(String fileName) throws IOException {
File f = new File(fileName);
FileReader file = new FileReader(f);
BufferedReader br = new BufferedReader(file);
while (br.ready()) {
String[] array = br.readLine().toString().split(","); //把读取的一行转为数组
getColor(array);
}
br.close();
file.close();
}
static void getColor(String[] buyRet){
int redCount = 0;
int blueCount = 0;
for (int i = 0; i < buyRet.length-1; i++) {
String str = buyRet[i];
for (int j = 0; j < open.length-1; j++) {
String openStr = open[j];
if(str.equals(openStr)){
redCount++;
continue;
}
}
//当循环结束时查看哪些相等
if(i==buyRet.length-2){
blueCount = buyRet[6].equals(open[6]) ? 1:blueCount;
if(redCount>0 || redCount>3){
System.out.print("red="+redCount +" blue="+blueCount);
for (int k = 0; k < buyRet.length; k++) {
System.out.print(" "+buyRet[k]+",");
}
System.out.println();
}
}
}
}
}
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class TestJava {
private static String[] open={"05","07","09","21","23","24","06"};
public static void main(String[] args) {
String path = "E:\\fangaiwen\\colordouble.txt";
try {
readFile(path);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Java读取文件按行读取
* @param fileName 文件路径
* @throws IOException
*/
public static void readFile(String fileName) throws IOException {
File f = new File(fileName);
FileReader file = new FileReader(f);
BufferedReader br = new BufferedReader(file);
while (br.ready()) {
String[] array = br.readLine().toString().split(","); //把读取的一行转为数组
getColor(array);
}
br.close();
file.close();
}
static void getColor(String[] buyRet){
int redCount = 0;
int blueCount = 0;
for (int i = 0; i < buyRet.length-1; i++) {
String str = buyRet[i];
for (int j = 0; j < open.length-1; j++) {
String openStr = open[j];
if(str.equals(openStr)){
redCount++;
continue;
}
}
//当循环结束时查看哪些相等
if(i==buyRet.length-2){
blueCount = buyRet[6].equals(open[6]) ? 1:blueCount;
if(redCount>0 || redCount>3){
System.out.print("red="+redCount +" blue="+blueCount);
for (int k = 0; k < buyRet.length; k++) {
System.out.print(" "+buyRet[k]+",");
}
System.out.println();
}
}
}
}
}
05,07,09,21,23,24,06
05,07,09,21,23,24,06
05,07,09,21,26,24,07
05,07,09,21,26,24,07本人喜欢买双色球彩票,每次一买就一百多注,开奖时一张张对好麻烦。就把每次买的彩票放在一个文件里,开奖时,一键运行就可以看到结果:
red=6 blue=1 05, 07, 09, 21, 23, 24, 06,
red=6 blue=1 05, 07, 09, 21, 23, 24, 06,
red=5 blue=0 05, 07, 09, 21, 26, 24, 07,
red=5 blue=0 05, 07, 09, 21, 26, 24, 07,
呵呵~~~