import java.util.Scanner;
/**
現(xiàn)在有兩個用戶輸入的字符串对湃,將這兩個字符串中重復的元素取出來賦給另一個字符串
@author 萬星明
@version 1.0
-
@time
*/
public class Work7 {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {System.out.println("請輸入字符串1:"); String st1 = sc.next(); System.out.println("請輸入字符串2:"); String st2 = sc.next(); System.out.println("重復字符串為:"+repeat(st1,st2));
}
public static String repeat(String st1,String st2) {
String s3 = "";
for(int i=0;i<st1.length();i++) {
for(int j=0;j<st2.length();j++) {
if(st1.charAt(i)==st2.charAt(j)) {
s3 = s3+st2.charAt(j);
}
}
}
return s3;
}
}