首页 > 代码库 > java实现归一数据化程序

java实现归一数据化程序

package org.ansj.test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.Vector;

/**
*
* 数据归一化
*
*/


public class GUIYi{

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
File fileName = new File("C:\\Users\\Administrator\\Desktop\\1.txt"); //这个是测试时用的语料文件,非用户输入
BufferedReader reader = new BufferedReader(new FileReader(fileName));

BufferedWriter bw =new BufferedWriter(new FileWriter("C:\\Users\\Administrator\\Desktop\\2.txt"));
//默认文件写入C盘下的TXT文档中,如需修改,改变路径即可。

String line;
int num=0;
double max = 0.0;

float sum = 0;
Vector<Integer> v=new Vector<Integer>();
while( ( line=reader.readLine() )!=null ){

Scanner scan=new Scanner(line);
String[] seg = line.split(" ");
float[] ds=new float[seg.length];
for(int i = 0; i<seg.length;i++)
{
ds[i]=Float.valueOf(seg[i]);
sum+=ds[i];

v.add(scan.nextInt());

}
// System.out.print(sum+" ");
for(float b:v){
float c;
c=b/sum;
System.out.print(c+" ");
}

num++;
System.out.print("\n");
v.clear();

}

reader.close();
bw.close();
}

}

java实现归一数据化程序