日期:2014-05-20 浏览次数:20959 次
public static void dd(int n) { for(int i=0;i<n;i++) { for(int j=0;j<=i+1;j++) { System.out.print("*"); } System.out.print("\n"); } for(int i=n;i>0;i--) { for(int j=0;j<i+1;j++) { System.out.print("*"); } System.out.print("\n"); } }
------解决方案--------------------
这样行不?
public class test{
public test(int len){
System.out.println(f(len,len,len));
}
public String f(int x,int y,int len){
return y<0?"":(x<=len/2-Math.abs(y-len/2-1)?"*":" ")+(x==len?"\n":"")+f(x==0?len:x-1,x==0?y-1:y,len);
}
public static void main(String args[]){
new test(7);
}
}
------解决方案--------------------
[code=java]
public class PrintSign{
private static final int N = 5;
public static void main(String[] args) {
for(int i=1; i <=N; i++) {
System.out.println(PrintSign.Sign(i));
}
for(int i=N; i>0; i--) {
System.out.println(PrintSign.Sign(i));
}
}
public static String Sign(int n) {
if (n == 1)
return "*";
else
return ("*" + Sign(n-1));
}
}
[/code]
------解决方案--------------------
public class PrintSign{ private static final int N = 5; public static void main(String[] args) { for(int i=1; i <=N; i++) { System.out.println(PrintSign.Sign(i)); } for(int i=N; i> 0; i--) { System.out.println(PrintSign.Sign(i)); } } public static String Sign(int n) { if (n == 1) return "*"; else return ("*" + Sign(n-1)); } }