演習
- ランダムに「ズン」もしくは「ドコ」を繰り返し出力しなさい。
- 「ズン」「ズン」「ズン」「ズン」「ドコ」の順番で出力されたら、そのあとに「キ・ヨ・シ!」と出力してからプログラムを終了しなさい。
Javaの講義、試験が「自作関数を作り記述しなさい」って問題だったから
「ズン」「ドコ」のいずれかをランダムで出力し続けて「ズン」「ズン」「ズン」「ズン」「ドコ」の配列が出たら「キ・ヨ・シ!」って出力した後終了って関数作ったら満点で単位貰ってた— てくも (@kumiromilk) 2016年3月9日
プログラム例
| 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 | package net.teachingprogramming.lecture02; /**  * ズンドコキヨシ  * http://teachingprogramming.net/  */ public class ZundokoKiyoshi {     public static void main(String[] args) {         int zun_count = 0;         while (true) {             double random = Math.random();             if (random < 0.7) {                 System.out.println("ズン");                 zun_count++;             } else {                 System.out.println("ドコ");                 if (zun_count >= 4) {                     System.out.println("キ・ヨ・シ!");                     break;                 }                 zun_count = 0;             }         }     } } |