コンソールの文字出力で周りに装飾をつけてみる。
コンソールの種類によって表示方法が変わるので外枠のサイズを決める部分はあまり真面目に作っていない。
ソースはネストが深くなってしまった。
もっと綺麗にできそうだが疲れるのでやめた。
import java.util.*; import java.nio.charset.StandardCharsets; public class Main { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); String input = s.next(); String[] arr = input.split(""); int width = arr.length+2; //1 for(int row = 0; row < 3; row++){ for(int column = 0; column < width; column++){ if(row == 1 && column > 0 && column <= arr.length){ System.out.print(arr[column-1]); }else{ System.out.print(column%2==(row%2==0?0:1)?'■':'□'); } } System.out.println(); } //2 width = input.getBytes("Shift_JIS").length+1; for(int row = 0; row < 3; row++){ for(int column = 0; column < width; column++){ if(row == 1 && column > 0 && column <= arr.length){ System.out.print(arr[column-1]); }else if(row == 1 && column > arr.length && column != width -1){ continue; }else{ System.out.print(column%2==(row%2==0?0:1)?'■':'□'); } } System.out.println(); } } }
出力結果
■□■□■□■ □あいうえお□ ■□■□■□■ ■□■□■□■□■□■ □あいうえお□ ■□■□■□■□■□■