题目描述
思路分析
找规律
代码实现
package com.kuang.study.lanqiao;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int x = sc.nextInt();int y = sc.nextInt();char [][] arr = new char[y][y+x-1];// 给数组赋值.for (int i = 0; i < arr.length; i++) {for (int j = 0; j < arr[i].length; j++) {arr[i][j] = '.';}}// 从左上到右下for (int i = 0; i < arr.length; i++) {for (int j = i; j < i+x; j++) {arr[i][j] = '*';}}// 从右上到左下for (int i = 0; i < arr.length; i++) {for (int j = arr[i].length-i-1; j > arr[i].length-i-1 - x; j--) {arr[i][j] = '*';}}// 打印for (int i = 0; i < arr.length; i++) {for (int j = 0; j < arr[i].length; j++) {System.out.print(arr[i][j]);}System.out.println();}sc.close();}}