2012-11-11 19 views
0

我想用一个充满星号的数组来制作图片。问题是,我不知道如何让星号出现在某些坐标上。如果你能帮上忙,那会很棒。用阵列拍一张图片

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

*“make a picture”*您的意思是make [ASCII艺术](http://en.wikipedia.org/wiki/ASCII_art)(文字字符排列看起来像一个图像)或一个实际的['Image'](http://docs.oracle.com/javase/7/docs/api/java/awt/Image.html)或['BufferedImage'](http://docs.oracle.com /javase/7/docs/api/java/awt/image/BufferedImage.html)? *“如果你能帮上忙,那就太好了。”*如果你可以提出一个(特定的)问题,这也会很棒。你的问题是什么? –

+0

我需要安排星号看起来像一个图像。我不知道如何在特定坐标处放置星号(例如anArray [0] [2])。我在描述中忘记提及的是我也需要在星号之间留出空格。我希望你明白我在说什么。 – user1718272

+0

你想在ASCII艺术中画什么?数据来自哪里(例如,由您硬编码,由现有图像生成,由用户在参数中提供..)? –

回答

1

你只需要把符号放在anArray [i] [j] =“*”;在你想要的位置,铰孔位置填充空格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"); 
    } 
+0

那么,数组中的其他位置应该填充一个空格或其他东西。 – irrelephant

+0

是的,好点 – dreamcrash

+0

雅但我怎么让他们去一个特定的点,我是新来这个哈哈。 – user1718272