概要
vistaでandroid studio 1.0.1やってみた。
練習問題やってみた。
練習問題
ズンドコを実装せよ。
方針
- 乱数 new Random
写真
サンプルコード
public void run(View view) {
TextView tv = (TextView) findViewById(R.id.chage);
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);
if (zd.equals("ドコ"))
{
String check = sb.toString();
if (check.endsWith(success))
{
sb.append(" キヨシ!!");
break;
}
sb.setLength(0);
}
}
tv.setText(sb.toString());
}
以上。