0
3

More than 3 years have passed since last update.

Java スロットゲーム

Last updated at Posted at 2020-11-23

処女作です。
何かアウトプットしてみたいなと思っているときに、パチスロの広告を見て思いつきました。

意識したことは下記2点。
・何も見ずに書く
・if文、for文を必ず使う

テキスト1冊読んだだけの初心者ですので、お手柔らかにお願いします。

処理の内容

①箱3つの配列を用意
②それぞれにランダムな数字を格納
③3つの数字が等しいかを比較
④等しかった場合、それらが7であるかを判定
⑤結果を出力

slot.java
public class Slot {
    public static void main(String[] args){
        int slotArray[] = new int[3];
        for(int i=0; i<3; i++){
            slotArray[i] = (int)(Math.random() * 10);
            System.out.print(slotArray[i]);
        }

        if(slotArray[0] == slotArray[1] && slotArray[0] == slotArray[2]){
            if(slotArray[0] == 7){
                System.out.println();
                System.out.println("大当たりーーー!!!!");
            } else {
                System.out.println();
                System.out.println("当たり!");
            }
        } else {
            System.out.println();
            System.out.println("もう1回!");
        }
    }
}

終わりに

配列、型変換なども使えてよかったです(小並感)
こうしたらもっとよくなる、などありましたら教えていただけると嬉しいです!

0
3
1

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
0
3