Created
January 10, 2015 10:27
-
-
Save takanakahiko/667318f2195e8878ceac to your computer and use it in GitHub Desktop.
abcチャレンジ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hoge{ | |
public static void main(String args[]){ | |
int max = 500; //上限 | |
int hantei = 0; | |
int n = 0; | |
int i = 0; | |
for(i = 0; i < max; i++){ | |
n =(int)(Math.random()*3); | |
switch(n){ | |
case 0: | |
System.out.print("a"); | |
hantei = 0; | |
break; | |
case 1: | |
System.out.print("b"); | |
break; | |
case 2: | |
System.out.print("c"); | |
break; | |
} | |
if( hantei == n-1 ){ | |
hantei = n; | |
} | |
if(hantei == 3){ | |
System.out.println(); //改行 | |
break; //for文を強制的に抜ける | |
} | |
} | |
System.out.println(i+"回目で成功"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment