當前位置:編程學習大全網 - 編程軟體 - 在Java編程中,只用壹個for循環再加上遞歸編寫程序

在Java編程中,只用壹個for循環再加上遞歸編寫程序

public class stars{

public static void main(String args[]){

int rows,n;

rows=n=5;

printStars(n,rows);

}

public static void printStars(int n,int rows){

if(n==0){

return;

}else{

printStars(n-1,rows);

for(int i=0;i<rows;i++){

if(i<rows-n){

System.out.print(" ");}else{

System.out.print("* ");

}

}

System.out.println();

}

}

}

這個應該是正確的,妳試壹下吧,只用了壹個for循環

  • 上一篇:哪些單機遊戲可以被稱得上高端?
  • 下一篇:python 求最大值
  • copyright 2024編程學習大全網