java的循环问题

来源:百度知道 编辑:UC知道 时间:2024/06/22 11:59:07
怎么用循环打出
*
**
***
****
*****

要用while循环
只能用while 不能用for啊 要双循环

public class ttt{
public static void main(String[] args){
int i = 1;
int j = 0;
while(i < 6){
while(j < i){
System.out.print("*");
j++;
}
System.out.println();
j = 0;
i++;
}
}
}

int i=1;
while (i<6) do{
for (k=1;k<=i;k++) System.out.print("*");
System.out.println("");
i++;

}

int n=5;
int index = 0;
String str = "";
while(index <n){
str += "*";
System.out.println(str);
index++;
}

不过这样问题,你真该自己想,这样的问题都做不了,以后还怎么学JAVA

String str;
int i=0;
while(i<5){
str=str+"*";
System.out.println(str);
i++;
}