@java Blue Bridge Cup Group B Exercise Basics (30) second question: 01 string

@java Blue Bridge Cup Group B Exercise Basics (30) second question: 01 string

Keywords: cycling

Problem Description:

01 for a run length of 5 bits, each bit may be 0 or 1, a total of 32 possible. They are the first few:

00000

00001

00010

00011

00100

The 32 output requested by the string 01 sequentially from small to large.

Input format
present no input questions.
Output format of
the output line 32, in ascending order of a length of each line 01 of the string 5.
Sample Output
00000
00001
00010
00011
<following sections will be omitted>

Code:

public class Main{
public static void main(String[] args) {
for(int i=0;i<32;i++){
String s=Integer.toBinaryString(i);
int len=s.length();
if(len==5){
System.out.println(s);
}else{
int c=5-len;
StringBuffer b=new StringBuffer(s);
while(c>0){
b.insert(0,“0”);
c–;
}
System.out.println(b);
}
}
}
}

Published 29 original articles · won praise 1 · views 1104

Guess you like

Origin blog.csdn.net/DAurora/article/details/104155013