2017-09-28 8 views
-3

私は単純なミラープログラムを作成しましたが、これを変更するように求めました。ユーザー入力のあるJavaミラープログラム

まず、サイジングに静的な値を使用しました。今私はサイジングのユーザー入力を使用する必要があります。

これまでのところ、これは私が持っているものですが、どこでこれを行うべきかわかりません。 誰かがそれが偉大な助けになるならば。

私が入手したユーザー入力は、そのサイズに使用されるはずです。

また、printspaces()という名前のメソッドを作成する必要があります。このメソッドは、スペースを印刷してスペースを印刷するために使用するスペースの数を指定します。

という名前のメソッドを作成します。このメソッドは、印刷するドットの数を指定し、ドットを印刷するために使用します。

プリントドットとプリントスペースを追加するにはどのようなコードを削除する必要がありますか?

おかげ

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("|"); 
     } 
    } 
} 

答えて

1

私はあなただけでそれらをユーザーの入力渡し、あなたの3つのメソッドをコールする必要があると思う:printspaces()printdots方法については

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

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

を、あなたはすでに、コードを持っていますドットとスペースを作成します。この名前で新しいメソッドを作成し、スペースとドットを現在印刷しているすべてのコードを適切なメソッドに移動し、現在印刷しているコードで呼び出します。

私はそれを試してみました。

これが役に立ちます。

関連する問題