備忘録

ソフトウェアエンジニアのメモ帳

文字を出力してみる

- 質問

Java 言語を使って、すべてのWindows-31J文字を表示したい

 

- 回答

import java.io.UnsupportedEncodingException;

public class Windows31JCharacterDisplay {
    public static void main(String args) {
        try {
            // Windows-31Jのバイト配列を生成
            byte
windows31JBytes = new byte[2];
            for (int i = 0x81; i <= 0x9F; i++) {
                windows31JBytes[0] = (byte) i;
                for (int j = 0x40; j <= 0xFC; j++) {
                    // 0x7Fを飛ばす
                    if (j == 0x7F) {
                        continue;
                    }
                    windows31JBytes[1] = (byte) j;

                    // バイト配列を文字列に変換して表示
                    String windows31JCharacter = new String(windows31JBytes, "Windows-31J");
                    System.out.print(windows31JCharacter + " ");
                }
                System.out.println();
            }

            for (int i = 0xE0; i <= 0xFC; i++) {
                windows31JBytes[0] = (byte) i;
                for (int j = 0x40; j <= 0xFC; j++) {
                    // 0x7Fを飛ばす
                    if (j == 0x7F) {
                        continue;
                    }
                    windows31JBytes[1] = (byte) j;

                    // バイト配列を文字列に変換して表示
                    String windows31JCharacter = new String(windows31JBytes, "Windows-31J");
                    System.out.print(windows31JCharacter + " ");
                }
                System.out.println();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}