Blue Bridge Cup: basic exercise 01 String "Java Algorithm implementation"

Source: Internet
Author: User

Title Description

For a 01-string length of 5 bits, each bit can be 0 or 1, a total of 32 possible. The first few of them are:

00000
00001
00010
00011
00100

Please output these 32 kinds of 01 strings in order from small to large.

Input format

This question is not entered.

Output format

Output 32 rows, in order from small to large, each line is a length of 5 01 strings.

Sample output

00000
00001
00010
00011
00100

< The following sections omit >

public class Main {public static void main (string[] args) {//scanner cin = new Scanner (system.in); int n1=0,n2=0,n3=0,n4=0, n5=0;for (int i=0;i<32;i++) {if (i%2==0) N1=0;else n1=1;if (i/2%2==0) n2=0;else n2=1;if (i/4%2==0) n3=0;else n3=1;if (i/ 8%2==0) N4=0;else n4=1;if (i/16%2==0) N5=0;else n5=1; System.out.println (n5+ "" +n4+ "" +n3+ "" +n2+ "" +n1);}}}
<pre name= "code" class= "Java" >public class main {public static void Main (string[] args) {//Scanner cin = new Scanne R (system.in); string[] n = new String[5];for (int i = 0; i <; i++) {int II = i;for (int j = 0; J < 5; J + +) {n[j]=ii%2+ ""; ii = i I/2;} System.out.println (N[4]+n[3]+n[2]+n[1]+n[0]);}}

Blue Bridge Cup: basic exercise 01 String "Java Algorithm implementation"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.