Java 用户输入的镜像程序

Java Mirror program with user input

我做了一个简单的镜像程序,现在让我修改。

起初我使用静态值来调整大小。现在我需要使用用户输入来调整大小。

到目前为止,这就是我所拥有的,但我不确定该去哪里。 如果有人可以提供帮助,那就太好了。

我得到的用户输入应该用于尺寸。

我还需要创建一个名为 printspaces() 的方法,该方法采用一个参数来表示要打印的空格数,并使用它来打印空格。

创建一个名为 printdots() 的方法,该方法采用一个参数来表示要打印的点数,并使用它来打印这些点。

我需要删除什么代码才能添加打印点和打印空间?

谢谢

package Whosebug;

import java.util.Scanner;

public class Mirror_2 {
    public static void main(String[] args) {
        line(0);
        top(0);
        bottom(0);
        line(0);
        int SIZE;

        Scanner Console = new Scanner(System.in);
        System.out.print("Please enter Size: ");
        int SIZE1 = Console.nextInt();
        System.out.println("You entered integer " + SIZE1);

    }

    public static void line(int SIZE) {
        // To change the lines at the bottom and top
        System.out.print("#");
        for (int i = 1; i <= SIZE * 4; i++) {
            System.out.print("=");
        }
        System.out.println("#");
    }

    public static void top(int SIZE) {
        // To change the top portion of the ASCII Art
        for (int line = 1; line <= SIZE; line++) {
            System.out.print("|");

            for (int space = 1; space <= (line * -2 + SIZE * 2); space++) {
                System.out.print(" ");
            }

            System.out.print("<>");

            for (int dot = 1; dot <= (line * 4 - 4); dot++) {
                System.out.print(".");
            }

            System.out.print("<>");

            for (int space = 1; space <= line * -2 + SIZE * 2; space++) {
                System.out.print(" ");
            }

            System.out.println("|");
        }
    }

    public static void bottom(int SIZE) {
        // To change the bottom portion of the ASCII Art
        for (int line = SIZE; line >= 1; line--) {
            System.out.print("|");

            for (int space = 1; space <= line * -2 + SIZE * 2; space++) {
                System.out.print(" ");
            }

            System.out.print("<>");

            for (int dot = 1; dot <= line * 4 - 4; dot++) {
                System.out.print(".");
            }

            System.out.print("<>");

            for (int space = 1; space <= line * -2 + SIZE * 2; space++) {
                System.out.print(" ");
            }

            System.out.println("|");
        }
    }
}

我认为你只需要调用你的三个方法将用户输入传递给它们:

    System.out.println("You entered integer " + SIZE1);

    // Add these three lines    
    line(SIZE1);
    top(SIZE1);
    bottom(SIZE1);
}

至于 printspaces()printdots 方法,您已经有了创建点和空格的代码。只需使用此名称创建新方法并将当前打印空格和点的所有代码移动到适当的方法中,并在当前打印它们的代码中调用它们。

当我尝试时对我有用。

希望对您有所帮助。