Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有用户输入的Java镜像程序_Java_Mirror - Fatal编程技术网

带有用户输入的Java镜像程序

带有用户输入的Java镜像程序,java,mirror,Java,Mirror,我做了一个简单的镜像程序,现在我被要求修改它 首先,我使用一个静态值来调整大小。现在我需要使用用户输入来调整大小 到目前为止,这是我所拥有的,但我不知道该怎么做。 如果有人能帮忙,那就太好了 我得到的用户输入应该用于大小 我还需要创建一个名为printspaces的方法,该方法接受一个参数,该参数表示要打印多少个空间,并使用它来打印这些空间 创建一个名为printdots的方法,该方法接受一个参数,表示要打印多少个点,并使用它来打印这些点 添加打印点和打印空间需要删除哪些代码 谢谢 packag

我做了一个简单的镜像程序,现在我被要求修改它

首先,我使用一个静态值来调整大小。现在我需要使用用户输入来调整大小

到目前为止,这是我所拥有的,但我不知道该怎么做。 如果有人能帮忙,那就太好了

我得到的用户输入应该用于大小

我还需要创建一个名为printspaces的方法,该方法接受一个参数,该参数表示要打印多少个空间,并使用它来打印这些空间

创建一个名为printdots的方法,该方法接受一个参数,表示要打印多少个点,并使用它来打印这些点

添加打印点和打印空间需要删除哪些代码

谢谢

package stackoverflow;

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方法,您已经有了创建点和空间的代码。只需创建具有此名称的新方法,并将当前打印空格和点的所有代码移动到适当的方法中,并在当前打印它们的代码中调用它们

当我尝试它时,它为我工作

希望这有帮助