Created
March 2, 2014 19:46
-
-
Save slava-konashkov/9312708 to your computer and use it in GitHub Desktop.
Программа рисует снежинку
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package cycles; | |
| public class Snowflake { | |
| public static void main(String[] args) { | |
| int iLen = 10; | |
| char[][] arrSnow; | |
| arrSnow = makeSnowflake(iLen); | |
| showSnowflake(arrSnow); | |
| } | |
| private static char[][] makeSnowflake(int iLenght) { | |
| iLenght = ((iLenght >> 1) << 1) + 1; | |
| char[][]snow = new char[iLenght][iLenght]; | |
| for (int i = 0; i <snow.length; i++) { | |
| for (int j = 0; j < snow.length; j++) { | |
| snow[i][j] = ' '; | |
| } | |
| } | |
| for (int i=0; i<iLenght; i++) { | |
| snow[i][i] = 'X'; | |
| snow[i][iLenght - 1 - i] = 'X'; | |
| snow[i][iLenght >>1] = 'X'; | |
| snow[iLenght >>1][i] = 'X'; | |
| } | |
| return snow; | |
| } | |
| private static void showSnowflake(char[][] snow) { | |
| for (char[] i : snow) { | |
| for (char j : i) { | |
| System.out.print(" " + j + " "); | |
| } | |
| System.out.println(""); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment