LoginSignup
1
2

More than 5 years have passed since last update.

例のキヨシチェックを java で

Last updated at Posted at 2016-03-11

java 勉強中なので、例のズンドコキヨシチェッカーを書きました

元ネタ

import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class ZunDoko {
    public static void main(String... args) {
        final String success = "ズンズンズンズンドコ";
        final List<String> zundoko = Arrays.asList("ズン", "ドコ");
        StringBuilder sb = new StringBuilder();
        Random rand = new Random();
        while (true) {
            String zd = zundoko.get(rand.nextInt(2));
            sb.append(zd);
            System.out.print(zd);
            if (zd.equals("ドコ")) {
                String check = sb.toString();
                if (check.endsWith(success)) {
                    System.out.println("キヨシ!");
                    break;
                }
                sb.setLength(0);
                System.out.println("");
            }
        }
    }
}

普通ですかねー。これで。

1
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2