Java打印常见图形

时间:2021-01-02 11:09:41
package org.other;



import java.util.Scanner;


/*
 * 题目:打印常用图形逻辑
 */
public class Ninthninth {
public static void main(String[] args) {

holl_Triangle(10);
   
}
private static void holl_Triangle(int num){
           for (int i = 0; i < num; i++) {
if (i!=num-1) {
for (int j = 0; j < 2*num-1; j++) {
if (j==num+i-1||j==num-i-1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
} else {
for (int j = 0; j < 2*num-1; j++) {
System.out.print("*");
}
}
System.out.println();
}
}
private static void M8() {
// 打印平行四边形
for (int i = 0; i < 10; i++) {
for (int j = 10; j > i; j--) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 1; j++) {
System.out.print("*");
}
for (int j = 22; j > 2 * i + 1; j--) {
System.out.print("*");
}
System.out.println();
}
}


private static void M7() {
// 打印空心正方形
Scanner sc = new Scanner(System.in);
System.out.println("请输入的你要打印的大小!");
int num = sc.nextInt();
for (int x = 0; x < num; x++) {
for (int y = 0; y < num; y++) {
// x=0 y=0 控制上下两条线
// num-1=x num-1=y 控制左右两条线
if (x == 0 || y == 0 || num - 1 == x || num - 1 == y) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}


private static void M6() {
// 打印菱型
// 上部分
for (int i = 0; i < 10; i++) {
for (int j = 10; j > i; j--) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 1; j++) {
System.out.print("*");
}
System.out.println();
} // 下部分
for (int i = 0; i < 10; i++) {
for (int j = 0; j < i; j++) {
System.out.print(" ");
}
for (int j = 22; j > i * 2 + 1; j--) {
System.out.print("*");
}
System.out.println();
}
}


private static void M5() {
// 等腰三角形
for (int i = 0; i < 9; i++) {
for (int j = 9; j > i; j--) {
System.out.print(" ");


}
for (int j2 = 0; j2 < 2 * i + 1; j2++) {
System.out.print("*");
}
System.out.println();


}
}


private static void M4() {
// 倒三角
for (int i = 0; i < 9; i++) {
for (int j = 9; j > i; j--) {
System.out.print("*");
}
System.out.println();
}
}


private static void M3() {
// 三角形
for (int i = 0; i < 10; i++) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
}


private static void M2() {
// 下三角
for (int i = 0; i <= 9; i++) {
for (int j = 0; j <= i; j++) {
System.out.println(j + "*" + i + "=" + j * i);
}
System.out.println();
}
}


private static void M1() {
// 矩阵三角
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {


}
System.out.println();
}
}


}