WUSTOJ 1290: 01字串(Java)

题目链接:🔗1290: 01字串
Description

 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:
 00000
 00001
 00010
 00011
 00100
 请按从小到大的顺序输出这32种01串。

Input

 本试题没有输入。

Output

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

Sample Input
本试题没有输入。
Sample Output
00000
00001
00010
00011
<以下部分省略>
代码💻
/**
 * Time 172ms
 * @author wowpH
 * @version 1.0
 * @date 2019年5月26日下午1:52:09
 * Environment:	Windows 10
 * IDE Version:	Eclipse 2019-3
 * JDK Version:	JDK1.8.0_112
 */

public class Main {
	public static void main(String[] args) {
		for (int i = 0; i < 32; i++) {
			String result = Integer.toBinaryString(i);
			for (int j = 5 - result.length(); j > 0; j--) {
				System.out.print("0");
			}
			System.out.println(result);
		}
	}
}
posted @ 2019-05-26 14:35  wowpH  阅读(185)  评论(0编辑  收藏  举报