【发布时间】:2014-08-28 12:36:18
【问题描述】:
我应该使用 for 循环和数组来制作一个程序,现在输出程序需要显示类似这样的内容
0-1-0-0-1-0-0-0-1-0-0-0-0-1
请注意,0 会在 1 的节目之后添加,到目前为止,我坚持使用此代码,您能帮帮我吗...
int[] binary = new int[150];
int b = 0;
int x = 3;
for(int a = 0; a < binary.length; a=a+2) {
box[a] =1;
}
for(int i =0; i < binary.length; i++){
for(b = 0; b < binary.length; b = b+x){
if(box[b] == 1) {
box[b] =0; // this condition changes the value of 1 to 0 if the binary is already "1".
}
else {
box[b] =1; // if the value of the binary is 0 it changes it to 1.
}
}
x++; // Putting this changes the value of the x making x=4 so that the next time the for loop runs it adds the int b to 4..(NOT SURE IF THIS IS RIGHT THOUGH)
}
for(int c =0; c < binary.length; c++) {
System.out.print(binary[c]); // "this should print the output "
}
我的问题是让它显示这样的东西
01001000100001000001
【问题讨论】:
-
当前输出是多少?
-
你真的需要弄清楚你想要完成什么。
-
@xgeorgekx 10110111 像这样它最多 150 所以如果全部写下来它就太长了
-
@IvanLorenzo 我已经添加了答案