Skip to content

Instantly share code, notes, and snippets.

@takanakahiko
Created January 10, 2015 10:27
Show Gist options
  • Save takanakahiko/667318f2195e8878ceac to your computer and use it in GitHub Desktop.
Save takanakahiko/667318f2195e8878ceac to your computer and use it in GitHub Desktop.
abcチャレンジ
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