丸三角四角

IT業界にしがみつく新人SEが立派なプログラマになろうともがく奮闘記

【Java】文字列を逆転表示_Ver3

コード更新致しました。

固有処理基底クラスを更新したので、更新したコードを紹介いたします。

import static java.lang.System.out;
import volume0.BaseExe;

public class ReverseSequence extends BaseExe {

    public static void main(String[] args) {
        new ReverseSequence().exeSysIn();
    }

    @Override
    protected void execute() throws Exception {
        StringBuffer str = new StringBuffer(nextLine());
        out.println(str.reverse());
    }
}

テストドライバは以下になります。

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import volume0.BaseTest;

public class ReverseSequenceTest extends BaseTest {

    private ReverseSequence rs;

    @Before
    public void setUp() throws Exception {
        super.setUp();
        rs = new ReverseSequence();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    @Test
    public void test() {
        rs.exeFileIn("./data/volume0_0006/in.txt");
        assertOutList("./data/volume0_0006/out.txt");
    }
}

テストドライバ内で使用している「in.txt」・「out.txt」の内容は以下になります。

in.txt
w32nimda
out.txt
admin23w

Ver1で問題の解説等を行なっているので、そちらも参照してください。

dadainu.hateblo.jp

アルゴリスムで困った時は、以下の本を参考にしてます。Javaに置き換えるのが少々難解ですが、、、

固有処理の基底クラスは以下の記事に記載していますので、参考にしてください。

dadainu.hateblo.jp

テストドライバで継承しているクラスは以下の記事に記載していますので、参考にしてみてください。

dadainu.hateblo.jp