※J.Y Chen 的個人部落格 ※

Just Follow Our Heart And We will shine!

63 瀏覽人次

【程式語言】JAVA的期中上機測驗 |TEST 2 輸入一整數 a 用 # 符號畫出 a 為邊長的倒直角空心三角形

Published: in JAVA by .

import java.util.Scanner;

public class midterm2 {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		System.out.print("Input a number,a:");
		int row = input.nextInt();
		for (int i = 1 ;  i <= row ; i++) {
			for (int j = 1 ; j <= row ; j++ ) {	
			if (i == 1 || j == row || j == i) {
				System.out.print("#");
			}
			else {
				System.out.print(" ");
				}
			}
			System.out.println("");
		}		
	}
}

Result:

©2019 - 2024 Henry Chen