我正在尝试使用充满星号的数组制作图片。问题是,我不知道如何使星号出现在某些坐标中。如果你能提供帮助那就太棒了。
public class Array {
public static void main (String[] args) {
horizontalLine();
}
public static void horizontalLine () {
String [][] anArray;
anArray = new String [2][8];
for (int i = 0; i < 2; i ++) {
for (int j = 2; j < 8; j ++) {
System.out.print ("*");
anArray [i][j] = "";
}
}
}
public static void picture () {
horizontalLine();
}
}
答案 0 :(得分:1)
您只需将符号放在anArray [i][j] = "*";
内的所需位置即可。使用spaces anArray [i][j] = " ";
(或其他符号)填充铰孔位置。填充anArray
后,只需将其打印出来即可。例如:
String [][] anArray = new String [N][M];
for ( i = 0; i < N; i ++)
for ( j = 0; j < M; j ++)
{
if(i == 0 || i == N-1 || j == 0 || j == M-1) anArray[i][j] = "*"; // Put * on the frame
else anArray[i][j] = " "; // Put spaces inside
}
for ( i = 0; i < N; i ++) //Print the picture
for ( j = 0; j < M; j ++)
{
printf("%s",anArray[i][j]);
if(j == M-1) printf("\n");
}