// 字串資料之比對 import java.io.*; public class n1a { public static void main(String args[]) throws Exception { //程式進入點 String getbr; int i,j,pt; int cnt_a,cnt_b;//A B情況的計數器 char now_a,now_b;//放兩個字串被取出來的那個字母 String stra="",strb=""; //分別放兩個字串 BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print("請輸入兩個字串:"); getbr = br.readLine(); if (getbr.equals("0")) //判斷結束 { System.out.println("結束!"); return; } //找空白分隔兩個字串 pt=getbr.indexOf(' '); if (pt<0) { System.out.println("非兩個字串!"); continue; } stra=getbr.substring(0,pt); strb=getbr.substring(pt+1); if (stra.length()!=strb.length()) { System.out.println("不等長!"); continue; } //System.out.print("stra="+stra+ " strb="+strb); stra=stra.toUpperCase(); //換大寫 strb=strb.toUpperCase(); cnt_a=0; cnt_b=0; for (i=0;i=0) { if (i==j) cnt_a=cnt_a+1; else cnt_b=cnt_b+1; } } if (cnt_a>0) System.out.print(cnt_a+"A"); if (cnt_b>0) System.out.print(cnt_b+"B"); if (cnt_a==0&&cnt_b==0) System.out.print("無相同字元"); System.out.println(); }//while 重複輸入 } }