我將如何使用三種方法來產生這樣的輸出?畫一個正方形?任何人都可以請解釋
Please enter the fill character: "z"
Please enter the size of the box (0 to 80): "3"
+---+
|zzz|
|zzz|
|zzz|
+---+
我的代碼能夠生成一個盒子,但是我有問題了解使用其他方法來創建它周圍的邊框。
import java.util.Scanner;
public class SolidBoxes
{
public static void main(String[] args)
{
int start = 0;
Scanner scan = new Scanner(System.in);
System.out.print("Please enter the fill character: ");
String character = scan.next();
System.out.print("Please enter the size of the box (0 to 80): ");
int size = scan.nextInt();
if (size > 80 || size < 0)
{
System.out.println("Please enter the size of the box (0 to 80): ");
size = scan.nextInt();
}
for (int i = 0; i < size; i++)
{
System.out.println();
for (int j = 0; j < size; j++)
{
System.out.print(character);
}
}
}
}
這使我的輸出:
Please enter the fill character: z
Please enter the size of the box (0 to 80): 3
zzz
zzz
zzz
怎麼可能添加其他兩種方法爲「+ - +」和另一種方法「|」?
您從*編碼* ..開始 –
謝謝羅素,是否可以使用三種不同的方法創建一個盒子? – Leroy
[你有什麼嘗試?](http://whathaveyoutried.com/) – ruakh