学习内容:
通过一道题目来学习使用循环嵌套。
例题:
解:
点击查看代码
import java.util.Scanner;
public class Main{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int row = 0; row < n; row++){
for(int col = 0; col < n; col++){
if(row == 0 || col == 0 || row == n - 1 || col == n - 1){
System.out.print("*");
}
else{
System.out.print(" ");
}
}
System.out.println();
}
sc.close();
}
}