您的位置:首页 > 编程语言 > Java开发

蓝桥杯(Java) 基础练习 01子串

2016-04-22 01:23 465 查看
// /*

// * 基础练习 01字串

// *

// * 问题描述

// * 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:

// * 00000

// * 00001

// * 00010

// * 00011

// * 00100

// * 请按从小到大的顺序输出这32种01串。

// * 输入格式

// * 本试题没有输入。

// * 输出格式

// * 输出32行,按从小到大的顺序每行一个长度为5的01串。

// *

// * 样例输出

// * 00000

// * 00001

// * 00010

// * 00011

// * <以下部分省略>

// * */

private static void BASIC_2() {
int a[] = new int[5];
int temp;
for (int i = 0; i < 32; i++) {
// System.out.println(Integer.toBinaryString(i));
temp = i;
a[0] = temp / 16;
temp = temp % 16;

a[1] = temp / 8;
temp = temp % 8;

a[2] = temp / 4;
temp = temp % 4;

a[3] = temp / 2;
temp = temp % 2;

a[4] = temp / 1;

for (int j = 0; j < a.length; j++) {
System.out.print(a[j]);
}
System.out.println();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: