public class Main{
// 定义一个静态字符串数组,每一行就是一次的数组输出
static String[] s1 = null;
public static void main(String[] args){
// 生成一行中第5、6个是*号其余为空格的行
change(5,6);
// 展示一次
show();
// 再展示一次
show();
// 生成全是*号的行
change(-1,-1);
show();
show();
// 同理
change(4,7);
show();
show();
}
// 改变数组的状态,决定一行中哪一个是*号哪一个是空格
// first是一行中第一次出现*号的索引,last则是最后一次
public static void change(int first,int last){
// 进来先把数组给初始化,里边都是默认值null
s1 = new String[12];
// 一行中不是*号就是空格
String x = "*";
String y = " ";
// 循环填充数组的值
for(int i = 0; i < s1.length; ++i){
// 这里是处理那些行中,有*号又有空格号的
if(first > 0){
s1[i] = y;
s1[first] = x;
s1[last] = x;
}else{
// 这里则处理那些全是*号的行
s1[i] = x;
}
}
}
// 这个函数主要用来输出数组
public static void show(){
for(String s: s1){
System.out.print(s);
}
System.out.println();
}
}