50,530
社区成员
发帖
与我相关
我的任务
分享
package test;
public class MyTest {
public static void main(String[] args) {
int M = (int)(Math.random()*100);
int N = (int)(Math.random()*100);
System.out.println(M+" "+N);
StringBuilder sb = new StringBuilder();
for(int x=0,y=0; x<M && y<N; ){
int k = ((int)(Math.random()*100))%2;
switch(k){
case 0:{
if(!sb.toString().endsWith("0")){
add0(sb);
x++;
}
continue;
}
case 1:{
if(!sb.toString().endsWith("11")){
add1(sb);
y++;
}
continue;
}
}
}
String str = new String(sb);
System.out.println(str);
}
public static void add0(StringBuilder sb){
sb.append("0");
}
public static void add1(StringBuilder sb){
sb.append("1");
}
}