0
有人可以幫我解決這個問題。我不知道如何對齊。我很感謝你的幫助。你能教我適當的代碼嗎..謝謝!如何對齊輸出?
目前代碼
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
public class Arff{
public static void main(String[] args) throws FileNotFoundException{
File TextFile = new File("weather.nominal.arff");
Scanner reader = new Scanner(TextFile);
while(reader.hasNextLine()){
String text = reader.nextLine();
String[] SplitData = text.split(" ");
if(SplitData[0].equals("@relation")){
System.out.println(SplitData[1]);
System.out.println();
}
if(SplitData[0].equals("@attribute")){
System.out.print(SplitData[1]+" ");
}
if(!SplitData[0].equals("@data") && !SplitData[0].equals("@attribute") && !SplitData[0].equals("@relation")){
System.out.println(SplitData[0].replace(',', ' '));
}
}
}
}
weather.symbolic.arff
@relation weather.symbolic
@attribute outlook {sunny, overcast, rainy}
@attribute temperature {hot, mild, cool}
@attribute humidity {high, normal}
@attribute windy {TRUE, FALSE}
@attribute play {yes, no}
@data
sunny,hot,high,FALSE,no
sunny,hot,high,TRUE,no
overcast,hot,high,FALSE,yes
rainy,mild,high,FALSE,yes
rainy,cool,normal,FALSE,yes
rainy,cool,normal,TRUE,no
overcast,cool,normal,TRUE,yes
sunny,mild,high,FALSE,no
sunny,cool,normal,FALSE,yes
rainy,mild,normal,FALSE,yes
sunny,mild,normal,TRUE,yes
overcast,mild,high,TRUE,yes
overcast,hot,normal,FALSE,yes
rainy,mild,high,TRUE,no
電流輸出:
weather.symbolic
outlook temperature humidity windy play
sunny hot high FALSE no
sunny hot high TRUE no
overcast hot high FALSE yes
rainy mild high FALSE yes
rainy cool normal FALSE yes
rainy cool normal TRUE no
overcast cool normal TRUE yes
sunny mild high FALSE no
sunny cool normal FALSE yes
rainy mild normal FALSE yes
sunny mild normal TRUE yes
overcast mild high TRUE yes
overcast hot normal FALSE yes
rainy mild high TRUE no
優選輸出:
weather.symbolic
outlook temperature humidity windy play
sunny hot high FALSE no
sunny hot high TRUE no
overcast hot high FALSE yes
rainy mild high FALSE yes
rainy cool normal FALSE yes
rainy cool normal TRUE no
overcast cool normal TRUE yes
sunny mild high FALSE no
sunny cool normal FALSE yes
rainy mild normal FALSE yes
sunny mild normal TRUE yes
overcast mild high TRUE yes
overcast hot normal FALSE yes
rainy mild high TRUE no
我怎樣才能添加\ t? – soyan
如何添加更多\ t?像這樣System.out.println(SplitData [0] .replace(',','\ t \ t')); – soyan
你corect,你必須做我'\ t \ t'或更多,如果需要的話。 –