Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.56 KB | None | 0 0
  1.  
  2. public class Banner {
  3.  
  4.     private static String[][] zahlen = {
  5.         {
  6.             "  ***   ",
  7.             " *   *  ",
  8.             "*     * ",
  9.             "*     * ",
  10.             "*     * ",
  11.             " *   *  ",
  12.             "  ***   ",
  13.             "        "
  14.         },
  15.        
  16.         {
  17.             "  *     ",
  18.             " **     ",
  19.             "* *     ",
  20.             "  *     ",
  21.             "  *     ",
  22.             "  *     ",
  23.             "*****   ",
  24.             "        "
  25.         },
  26.  
  27.         {
  28.             " *****  ",
  29.             "*     * ",
  30.             "      * ",
  31.             " *****  ",
  32.             "*       ",
  33.             "*       ",
  34.             "******* ",
  35.             "        "
  36.         },
  37.        
  38.         {
  39.             " *****  ",
  40.             "*     * ",
  41.             "      * ",
  42.             " *****  ",
  43.             "      * ",
  44.             "*     * ",
  45.             " *****  ",
  46.             "        "
  47.         },
  48.        
  49.         {
  50.             "*       ",
  51.             "*     * ",
  52.             "*     * ",
  53.             "******* ",
  54.             "      * ",
  55.             "      * ",
  56.             "      * ",
  57.             "        "
  58.         },
  59.    
  60.         {
  61.             "******* ",
  62.             "*       ",
  63.             "*       ",
  64.             "******  ",
  65.             "      * ",
  66.             "*     * ",
  67.             " *****  ",
  68.             "        "
  69.         },
  70.        
  71.         {
  72.             " *****  ",
  73.             "*       ",
  74.             "*       ",
  75.             "******  ",
  76.             "*     * ",
  77.             "*     * ",
  78.             " *****  ",
  79.             "        "
  80.         },
  81.        
  82.         {
  83.             "******* ",
  84.             "*    *  ",
  85.             "    *   ",
  86.             "   *    ",
  87.             "  *     ",
  88.             "  *     ",
  89.             "  *     ",
  90.             "        "
  91.         },
  92.        
  93.         {
  94.             " *****  ",
  95.             "*     * ",
  96.             "*     * ",
  97.             " *****  ",
  98.             "*     * ",
  99.             "*     * ",
  100.             " *****  ",
  101.             "        "
  102.         },
  103.        
  104.         {
  105.             " *****  ",
  106.             "*     * ",
  107.             "*     * ",
  108.             " ****** ",
  109.             "      * ",
  110.             "*     * ",
  111.             " *****  ",
  112.             "        "
  113.         }          
  114.     };
  115.    
  116.    
  117.     public static int getIntAt(String input, int pos) {
  118.         switch (input.charAt(pos)) {
  119.             case '0': return 0;
  120.             case '1': return 1;
  121.             case '2': return 2;
  122.             case '3': return 3;
  123.             case '4': return 4;
  124.             case '5': return 5;
  125.             case '6': return 6;
  126.             case '7': return 7;
  127.             case '8': return 8;
  128.             case '9': return 9;
  129.             default: return -1;
  130.         }
  131.     }
  132.  
  133.        
  134.     public static void main(String[] args) {   
  135.         //String input = args[0];
  136.         String input = "01234567891A";
  137.  
  138.         // Maximal 10 Zeichen ausgeben
  139.         int length = input.length();
  140.         if(length > 10) {
  141.             length = 10;
  142.         }
  143.        
  144.         // Erstmal nach Fehlern in der Eingabe suchen
  145.         // Dazu iterieren wir über den Eingabestring, d.h. wir schauen uns jeden Buchstaben
  146.         // genau an.
  147.         for (int position = 0; position < length; position++) {
  148.             String letter = input.substring(position, position+1);
  149.            
  150.             // Der komplizierte Ansatz /*
  151.             if( letter.equals("0") || letter.equals("1") || letter.equals("2") ||
  152.                 letter.equals("3") || letter.equals("4") || letter.equals("5") ||
  153.                 letter.equals("6") || letter.equals("7") || letter.equals("8") ||
  154.                 letter.equals("9"))
  155.             {
  156.                 continue;
  157.             }
  158.            
  159.             // An diese Stelle kommen wir nur, wenn die Eingabe nicht 012345678 oder 9 war
  160.             System.out.println("Could not parse input string. Only numbers allowed!");
  161.             System.exit(-1);           
  162.             // */
  163.            
  164.                    
  165.             // Der kürzere, aber für euch noch unbekannte Weg. Also kinda hacky.
  166.             /*
  167.            
  168.             // Versuche den Buchstaben an dieser Stelle zu einem Integer zu machen
  169.             // Falls das fehlschägt, Fehler ausgeben und beenden.
  170.             try {
  171.                 Integer.parseInt(letter);
  172.             } catch (Exception e) {
  173.                 System.out.println("Could not parse input string. Only numbers allowed!");
  174.                 System.exit(-1);
  175.             }
  176.             */
  177.         }
  178.        
  179.         // position is X
  180.         // row is Y
  181.         for (int row = 0; row < zahlen[0].length; row++) {
  182.             for (int position = 0; position < length; position++) {
  183.                 //int number = Integer.parseInt(input.substring(position, position+1));
  184.                 int number = getIntAt(input, position);
  185.                 System.out.print(zahlen[number][row]);
  186.             }
  187.             System.out.println();
  188.         }
  189.     }
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement