【程式語言】JAVA的期中上機測驗 |TEST 2 輸入一整數 a 用 # 符號畫出 a 為邊長的倒直角空心三角形
Published:
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("");
}
}
}