我想显示由星号组成的字母A。首先,程序将要求输入字母的大小,然后根据给定的大小将字母缩放为该大小。

到目前为止,这是我所拥有的,但是我不确定自己做错了什么。如您所见,它仅打印一行。任何帮助都会很棒。

码:

import java.util.Scanner;
public  class Problem7 {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int input, size, i;

        System.out.print("Enter a size: ");
        input = kbd.nextInt();

        while (input <= 1) {
            System.out.print("Enter a size: ");
            input = kbd.nextInt();
        }
        for (int col = 0; col < input; col++) {
            for (int row = 0; row < input; row++) {
                if (col == 1 || col == input || row == col)
                    System.out.print("*");
                else
                    System.out.print(" ");
            }
        }
    }
}


结果:

Enter a size: 5
*    *****  *     *     *

最佳答案

如果要换行,请使用:

System.out.print("\n");

09-30 14:57
查看更多