发布网友 发布时间:2022-05-16 02:51
共1个回答
热心网友 时间:2023-10-09 11:29
import java.util.Scanner;
public class Day05A {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
// 1.第一题
System.out.print("输入参数:");
int num = sc.nextInt();
for (int i = 0, count = 1; i < num; i++) {
for (int j = 0; j < num; j++) {
System.out.print(count++ + " ");
}
System.out.println();
}
System.out.println("-----------------");
int n=num>3&&num<11?num/3:num<1?0:4;
// 2.第二题:
for (int i = 0,x=0; i < num; i++) {
if(i<=num/2) {
x = i * 2 + 1;
}else {
x=num%i+(n--);
}
for (int j = num; j > x; j--) {
System.out.print(" ");
}
for (int j = 0; j < x; j++) {
System.out.print(" *");
}
System.out.println();
}
}
}