标签:public sys lse 整数 01字串 ann port 练习 pre
共32种可能,每种可能对应一个整型数,从小到大,把每一个整数转换成二进制位输出
1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class Main { 5 public static void main(String[] args) { 6 Scanner scanner = new Scanner(System.in); 7 8 int n1, n2, n3, n4, n5; 9 10 for (int i = 0; i < 32; i++) { 11 if (i % 2 == 0) { 12 n1 = 0; 13 } else { 14 n1 = 1; 15 } 16 if (i / 2 % 2 == 0) { 17 n2 = 0; 18 } else { 19 n2 = 1; 20 } 21 if (i / 4 % 2 == 0) { 22 n3 = 0; 23 } else { 24 n3 = 1; 25 } 26 if (i / 8 % 2 == 0) { 27 n4 = 0; 28 } else { 29 n4 = 1; 30 } 31 if (i / 16 % 2 == 0) { 32 n5 = 0; 33 } else { 34 n5 = 1; 35 } 36 System.out.print(n5); 37 System.out.print(n4); 38 System.out.print(n3); 39 System.out.print(n2); 40 System.out.print(n1); 41 System.out.println(); 42 } 43 44 } 45 }
标签:public sys lse 整数 01字串 ann port 练习 pre
原文地址:https://www.cnblogs.com/duniqb/p/10201179.html