基本情報技術者試験 午後対策 JAVA②

参考書のプログラムをただ書き写すだけのシリーズ
これ見ながらやってた

public class ReplaceWord{
public static void main(String[] args){
char[] originalStr = { 初期値 };
char[] searchWord = { 初期値 };
String replaceWord = 初期値;
int searchIndex = 0;
boolean wordMatching = false;

for(char c : originalStr){
if(c == searchWord[searchIndex++]) {
if(wordMatching == false) wordMatching = true;
if(searchIndex == searchWord.length){
System.out.print(replacedWord);
searchIndex = 0;
wordMatching = false;
} else {
if(wordMatching) {
for(int i = 0; i < searchIndex-1; i++) System.out.print(searchWord[i]); searchIndex = 0; if(c == searchWord[searchIndex]) searchIndex++; else { wordMatching = false; System.out.print(c); } } else { System.out.print(c); } } } } } }