1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Scanner sc = new Scanner(System.in); String S = sc.next(); String T = sc.next(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < T.length(); i++) { char c = T.charAt(i); if(c >= '0' && c <= '9'){ char replacement = ' '; switch(c){ case '0': replacement = S.charAt(0); break; case '1': replacement = S.charAt(1); break; case '2': replacement = S.charAt(2); break; case '3': replacement = S.charAt(3); break; case '4': replacement = S.charAt(4); break; case '5': replacement = S.charAt(5); break; case '6': replacement = S.charAt(6); break; case '7': replacement = S.charAt(7); break; case '8': replacement = S.charAt(8); break; case '9': replacement = S.charAt(9); break; default: break;
} sb.append(replacement); }else { sb.append(T.charAt(i)); }
} String str = sb.toString(); System.out.println(str);
sc.close();
|