面試題java 如何將科學計數法顯示在控制檯

代碼實現spa

@Test
    public void solution1() {
        String s0 = " - \n" + "| |\n" + "   \n" + "| |\n" + " - \n";
        String s1 = "   \n" + "|  \n" + "   \n" + "|  \n" + "   \n";
        String s2 = " - \n" + "  |\n" + " - \n" + "|  \n" + " - \n";
        String s3 = " - \n" + "  |\n" + " - \n" + "  |\n" + " - \n";
        String s4 = "   \n" + "| |\n" + " - \n" + "  |\n" + "   \n";
        String s5 = " - \n" + "|  \n" + " - \n" + "  |\n" + " - \n";
        String s6 = " - \n" + "|  \n" + " - \n" + "| |\n" + " - \n";
        String s7 = " - \n" + "  |\n" + "   \n" + "  |\n" + "   \n";
        String s8 = " - \n" + "| |\n" + " - \n" + "| |\n" + " - \n";
        String s9 = " - \n" + "| |\n" + " - \n" + "  |\n" + " - \n";
        String p = "   \n" + " ●\n" + "   \n" + " ●\n" + "   \n";

        String[] arr = {s0, s1, s2, s3, s4, s5, s6, s7, s8, s9};

        int hour = LocalTime.now().getHour();
        int minute = LocalTime.now().getMinute();
        String time = (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute);
        char[] chars = time.toCharArray();
        String[] a1 = arr[Integer.valueOf(String.valueOf(chars[0]))].split("\n");
        String[] a2 = arr[Integer.valueOf(String.valueOf(chars[1]))].split("\n");
        String[] a3 = arr[Integer.valueOf(String.valueOf(chars[3]))].split("\n");
        String[] a4 = arr[Integer.valueOf(String.valueOf(chars[4]))].split("\n");
        String[] pp = p.split("\n");

        for (int i = 0; i < 5; i++) {
            System.out.println(a1[i] + " " + a2[i] + " " + pp[i] + " " + a3[i] + " " + a4[i]);
        }
    }

結果 code

clipboard.png

相關文章
相關標籤/搜索