プログラマメモ2 - programmer no memo2

3789 -- バイナリークロック 2012/09/18

問題文を読まずにチャレンジ。
3789 -- Binary Clock

package p3789; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int i =1; while(n-- > 0){ String line = scanner.next(); String[] ss = line.split(":"); String s1 = toBinaryString(ss[0]); String s2 = toBinaryString(ss[1]); String s3 = toBinaryString(ss[2]); String s = s1+s2+s3; System.out.print(i++); System.out.print(" "); System.out.print(toVerticalStrgin(s)); System.out.print(" "); System.out.print(s); System.out.println(); } } static String toBinaryString(String ss){ int i = Integer.parseInt(ss); String s = Integer.toBinaryString(i); StringBuilder builder = new StringBuilder(); for(int j=s.length();j<6;j++){ builder.append("0"); } return builder.append(s).toString(); } static String toVerticalStrgin(String s){ StringBuilder builder = new StringBuilder(); for(int i=0;i<6;i++){ builder.append(s.charAt(i)); builder.append(s.charAt(6+i)); builder.append(s.charAt(12+i)); } return builder.toString(); } }

: