Java写出多种图形

平行四边形package com.test.demo;

public class pingxingsiibianxing {
public static void main(String[] args) {
for(int i=0;i<5;i++){
for(int j=4;j>i;j–){
System.out.print(" “);
}
for(int j=0;j<8;j++){
System.out.print(”*");
}
System.out.println();
}
}
}

倒三角形

package com.test.demo;

public class DaoSanJiao {
public static void main(String[] args) {
printDengyao(10);
}
public static void printDengyao(int x) {
for (int i = 0; i < x; i++) {
System.out.println();
for (int j = 0; j < i + 1; j++) {
System.out.print(" “);
}
for (int j = i; j < x; j++) {
System.out.print(”* ");
}
}
}
}

菱形

package com.test.demo;

import java.util.Scanner;

public class lingxing {
public static void main(String[] args) {
int i,j,n;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
for(i=1;i<=2n-1;i++){
for(j=1;j<=Math.abs(n-i);j++){
System.out.print(" ");
}
for(j=1;j<=2
n-1-2Math.abs(n-i);j++){
System.out.print("
");
}
System.out.println();
}
}

}

等腰三角形

package com.test.demo;

public class dengyaosanjiaoxing {
public static void main(String[] arges){
for (int i = 1; i <= 9; i++)
{

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

}

你可能感兴趣的:(多样化demo,图形化,基础类,图形,幽默性)