(java程序编写)利用循环结构,编写程序打印出一个以“*”组成的菱形。

来源:百度知道 编辑:UC知道 时间:2024/07/02 23:59:34
(java程序编写)利用循环结构,编写程序打印出一个以“*”组成的菱形。

public class Star
{
public static void main(String[] args)
{

for(int h=0;h<=5;h=h+2)
{

for(int u=0;u<6-h;u++)
{
System.out.print(" ");
}
for(int g=5;g>=5-h;g--)
{
System.out.print("*"+" ");
}
System.out.println();

}
for(int i=1;i<=7;i=i+2)
{
for(int j=8-i;j>0;j--)
{
System.out.print("*"+" ");
}
System.out.println();
for(int k=0;k<=i;k++){
System.out.print(" ");
}
}
}
}

public class jtest1{
public jtest1(){
}
public static void main(String[] args)
{
for(int i=0;i<5;i++){
for(int k=0;k<=i;k++){
System.out.print(" ");
}
for(int j=0;j<10;j++){
Syste