字串

问题描述
对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:
00000
00001
00010
00011

00100

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

输入格式

本试题没有输入。
输出格式
输出32行,按从小到大的顺序每行一个长度为5的01串。
样例输出
00000
00001
00010

00011

public class Main{
  static char[] binaryArray = new char[5];
  static char [] chs = {'0','1'};
  public static void main(String[]args)throws Exception{
     for(int i=0;i<32 ; i++){
      System.out.println(fun(i));
     }
   }
   public static String fun(int a){
    for (int i=4 ;i>=0 ;i-- ){
        binaryArray[i] = chs[a & 1];
        a=a>>>1;
    }
      return new String(binaryArray);
   }
}



猜你喜欢

转载自blog.csdn.net/u012651389/article/details/44758515