public class Banner { private String text=""; private char style='#'; public Banner(String text,char style){ this.text=text; this.style=style; } public void setStyle(char style){ this.style=style; } public void display(){ String[] A={" ## ","# # ","#### ","# # ","# # "}; String[] E={ "#### ", "# ", "#### ", "# ", "#### "}; String[] C={ "#### ", "# ", "# ", "# ", "#### "}; String[] S={ "#### ", "# ", "#### ", " # ", "#### "}; int j=0; while (j<5){ int i=0; while (i<this.text.length()){ if (this.text.charAt(i)=='A'){ A[j]=replace_one(A[j],'#',this.style); System.out.print(A[j]); } if (this.text.charAt(i)=='E'){ E[j]=replace_one(E[j],'#',this.style); System.out.print(E[j]); } if (this.text.charAt(i)=='C'){ C[j]=replace_one(C[j],'#',this.style); System.out.print(C[j]); } if (this.text.charAt(i)=='S'){ S[j]=replace_one(S[j],'#',this.style); System.out.print(S[j]); } i+=1; } System.out.println(); j+=1; } } public String replace_one(String t,char s,char r){ StringBuilder temp = new StringBuilder(t); for (int i=0;i<t.length();i++){ if (t.charAt(i)=='#'){ temp.setCharAt(i,r); } } return temp.toString(); } public static void main(String[] args){ Banner B = new Banner("AEC",'x'); B.display(); B.setStyle('o'); B.display(); } }
วันจันทร์ที่ 2 พฤศจิกายน พ.ศ. 2558
Lab08 : String to Text [Java]
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
commit เพิ่มเติม : เพื่ม userstory, bookmark
>> add userstory ทำการเพิ่ม userstory ใน functional tests >> add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...
-
1 2 3 4 5 6 7 8 9 def setup (): print (d2b( 8 )) def d2b (num): x = "" while num > 0 : x = str ( int (n...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 def test_layout_and_styling ( self ): # Edith goes to the home page self . brow...
-
การใช้ template inheritence คือการสืบทอดเทมเพลต เพื่อให้ไม่ต้องเขียนโค้ดหน้าเว็บๆซ้ำๆ เราจะมีหน้าหลักอันเดียว (base.html or parent) ภายในนั...
ไม่มีความคิดเห็น:
แสดงความคิดเห็น