Unicode Tabelle in vertikalen Spalten ausgeben

DannyDaniel

Mitglied
Hallo Zusammen!

Wie kann ich am besten und einfachsten mit 2 for-Schleifen (und im nächsten Schritt mit 1 for-Schleife) eine Unicode-Tabelle in vertikalen Spalten ausgeben? (siehe Anhang). Ich habe aktuell diesen Code, der mir allerdings sehr umständlich vorkommt. Wäre dankbar für Tipps.

Java:
for (int i = 32; i <= 87; i++) {
            for (int j = i; j <= i + 168; j = j + 56) {
                System.out.printf("%5d ", j);
                System.out.print((char) j);
            }
            System.out.println();
        }

unicode.JPG
 
Zuletzt bearbeitet:

MoxxiManagarm

Top Contributor
Java:
public class PrintInColumnsDemo {
    private static int ROWS_TO_PRINT = 10;
    private static int NUMBERS_TO_PRINT = 55;
 
    public static void main(String... args) {
        int columns_to_print = (NUMBERS_TO_PRINT / ROWS_TO_PRINT) + 1;
     
        for(int i = 1; i <= ROWS_TO_PRINT; i++) {
            for(int j = 0; j < columns_to_print; j++) {
                int number = j * ROWS_TO_PRINT + i;
             
                if (number <= NUMBERS_TO_PRINT)
                    System.out.printf("%5d ", number);
            }
         
            System.out.println();
        }
    }
}

Code:
    1    11    21    31    41    51 
    2    12    22    32    42    52 
    3    13    23    33    43    53 
    4    14    24    34    44    54 
    5    15    25    35    45    55 
    6    16    26    36    46 
    7    17    27    37    47 
    8    18    28    38    48 
    9    19    29    39    49 
   10    20    30    40    50
 

MoxxiManagarm

Top Contributor
Gleiche Demo mit einer Schleife:

Java:
public class PrintInColumnsDemo {
    private static int ROWS_TO_PRINT = 10;
    private static int NUMBERS_TO_PRINT = 55;
   
    public static void main(String... args) {
        int columns_to_print = (NUMBERS_TO_PRINT / ROWS_TO_PRINT) + 1;
       
        for(int x = 0; x < NUMBERS_TO_PRINT; x++) {
            int j = x % columns_to_print;
            int i = (x / columns_to_print) + 1;
           
            int number = j * ROWS_TO_PRINT + i;
           
            if (number <= NUMBERS_TO_PRINT) {
                System.out.printf("%5d ", number);
           
                if (number + ROWS_TO_PRINT > NUMBERS_TO_PRINT)
                    System.out.println();
            }
        }
    }
}

Aber ganz ehrlich, die 2 Schleifen finde ich an der Stelle deutlich sinnvoller. Schleifen einsparen ist nicht immer besser.
 

Neue Themen


Oben