问题描述 编写一个程序,首先输入一个整数,例如5,然后在屏幕上显示如下的图形(5表示行数): * * * * * * * * * * * * * * *
import java.util.Scanner; /* * 注意输入的数是否小于等于0。若是输出空格 */ public class Main { public static void Print(int n){ System.out.print("*"); for ( int i = 1 ; i < n ; i++){ System.out.print(" *"); } } public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int N = in.nextInt(); if(N <= 0){ System.out.print(" "); }else{ Print(N); for ( int i = N-1 ; i > 0 ; i--){ System.out.println(); Print(i); } } in.close(); } } ---来自腾讯云社区的---AI那点小事
微信扫一扫打赏
支付宝扫一扫打赏