📄 data.java
字号:
import java.io.FileReader;
import java.util.ArrayList;
public class data {
public double[] Xaxis;
public double[] Yaxis;
public int[] XYClass;
public double[] Xtest;
public double[] Ytest;
public int[] XYtest;
public data(){
Xaxis = new double[10000];
Yaxis = new double[10000];
XYClass = new int[10000];
Xtest = new double[500];
Ytest = new double[500];
XYtest = new int[500];
}
public boolean readDataFromFile(){
FileReader input = null;
try{
input = new FileReader("train.txt");
int code = 0;
boolean note = false;
ArrayList list = new ArrayList();
//int arrayIndex = 0;
int index = 0;
while((code = input.read()) != -1){
if(code == 13){
//temp[arrayIndex] = 0;
Object[] temp = list.toArray();
char[] cTemp = new char[temp.length];
for(int i = 0 ; i < temp.length; i++){
cTemp[i] = (Character)temp[i];
}
String sTemp = new String(cTemp);
String[] sArray = sTemp.split(" ");
Xaxis[index] = Double.parseDouble(sArray[0]);
Yaxis[index] = Double.parseDouble(sArray[1]);
XYClass[index] = Integer.parseInt(sArray[2]);
index += 1;
list.clear();
}
else{
list.add((char)code);
}
}
modify();
return true;//outputData();
}catch(Exception e){
e.getMessage();
System.out.println("damn");
}finally{
try{
input.close();
}catch(Exception e2){
e2.getMessage();
}
}
return false;
}
////////////////////////////////////////////////////////////////
private void modify(){
for(int i = 0; i < 10000; i++){
if(XYClass[i] == 0)
XYClass[i] = -1;
}
}
////////////////////////////////////////////////////////////////
public boolean readTest(){
FileReader input = null;
try{
input = new FileReader("test.txt");
int code = 0;
boolean note = false;
ArrayList list = new ArrayList();
//int arrayIndex = 0;
int index = 0;
while((code = input.read()) != -1){
if(code == 13){
//temp[arrayIndex] = 0;
Object[] temp = list.toArray();
char[] cTemp = new char[temp.length];
for(int i = 0 ; i < temp.length; i++){
cTemp[i] = (Character)temp[i];
}
String sTemp = new String(cTemp);
String[] sArray = sTemp.split(" ");
Xtest[index] = Double.parseDouble(sArray[0]);
Ytest[index] = Double.parseDouble(sArray[1]);
XYtest[index] = Integer.parseInt(sArray[2]);
index += 1;
list.clear();
}
else{
list.add((char)code);
}
}
modify2();
return true;//outputData();
}catch(Exception e){
e.getMessage();
System.out.println("damn");
}finally{
try{
input.close();
}catch(Exception e2){
e2.getMessage();
}
}
return false;
}
private void modify2(){
for(int i = 0; i < 500; i++){
if(XYtest[i] == 0)
XYtest[i] = -1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -