填空题先理解题意,再不断地debug
答案:s.substring(0,s.length()-3)
package pastExamPaper;
/*
打印菱形(填空题) 极限思维推导,在推导的过程中找规律!
*/
public class Demo40 {
public static void main(String[] args) {
f(8);
}
private static void f(int n){
String s = "*";
for ( int i = 0; i < 2*n-3; i++ ){
s += ".";
}
s += "*";
String s1 = s + "\n";
String s2 = "";
for ( int i = 0; i < n-1; i++ ){
//填空
s = "." + s.substring(0,s.length()-3) +"*";
s1 = s + "\n" +s1;
s2 += s+"\n";
}
System.out.println(s1+s2);
}
}