我目前正在学习如何打印带有数据的文本区域,但是在尝试想办法删除具有空值的行时遇到了麻烦
String color1 = "";
String color2 = "";
String color3 = "";
String color4 = "";
String color5 = "";
String color6 = "";
String color7 = "";
String color8 = "";
int weight1 = 0;
int weight2 = 0;
int weight3 = 0;
int weight4 = 0;
int weight5 = 0;
int weight6 = 0;
int weight7 = 0;
int weight8 = 0;
TextArea.setText("COLOR\t\t:\t WEIGHT:" +
"\n=====================================\n" +
color1 +"\t\t\t "+ weight1 + "\n" +
color2 +"\t\t\t "+ weight2 + "\n" +
color3 +"\t\t\t "+ weight3 + "\n" +
color4 +"\t\t\t "+ weight4 + "\n" +
color5 +"\t\t\t "+ weight5 + "\n" +
color6 +"\t\t\t "+ weight6 + "\n" +
color7 +"\t\t\t "+ weight7 + "\n" +
color8 +"\t\t\t "+ weight8 );
}
通常,只有 color1 和 color2 及其权重才有值,很少达到 color8。虽然 color8 及其权重没有值,但我如何确保它只有在有值时才显示在 textarea 中?