Jump to content
Hostul a fost schimbat. Daca vedeti serverul offline readaugati rpg.b-zone.ro sau 141.95.124.78:7777 in clientul de sa-mp ×

[JAVA] Binary Number Pattern


Tupi
 Share

Recommended Posts

for(int i = 1; i <= 8; i++) {
    int num;

    if(i % 2 == 0) {
       num = 0;
       for(int j = 1; j <= 8; j++) {
           System.out.print(num);
           num = (num == 0) ? 1 : 0;
       }
    }
    else {
       num = 1;
       for (int j = 1; j <= 8; j++) {
            System.out.print(num);
            num = (num == 0) ? 1 : 0;
       }
    }
    System.out.println();
}

 

Output:

10101010
01010101
10101010
01010101
10101010
01010101
10101010
01010101

 

Edited by Tupi
Link to comment
Share on other sites

  • Tupi changed the title to [JAVA] Binary Number Pattern
  • Tupi locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.