Skip to main content
deleted 75 characters in body
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384

Java 711, 68 6565 29 bytes

void c(int i){for(int x=0;x++<i;)System.out.print(i%2<1?92:'/');}
n->(n%2<1?"\\":"/").repeat(n)

3-3 bytes saved thanks to @user902383 and @SeanBean.

Just like with this answer, the shortest code-golf seems to loop and print. Both recursive and
void c(int i){System.out.print(new String(new char[i]).replace("\0",i%2<1?"\\":"/"));}
seems-36 bytes switching from Java 7 to be longer.Java 11+

Ungolfed & test code:Try it online.

Try it here.

class M{
  static void c(int i){
    for(int x = 0; x++ < i;){
      System.out.print(i % 2 < 1
                        ? 92
                        : '/');
    }
  }

  public static void main(String[] a){
    for(int i = 0; i < 10; i++){
      c(i);
      System.out.println();
    }
  }
}

OutputExplanation:

/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////
n->                     // Method with integer parameter and String return-type
  (n%2<1?               //  If `n` is even:
         "\\"           //   Use String "\"
        :               //  Else (`n` is odd):
         "/")           //   Use String "/" instead
             .repeat(n) //  Repeat it `n` amount of times

Java 7, 68 65 bytes

void c(int i){for(int x=0;x++<i;)System.out.print(i%2<1?92:'/');}

3 bytes saved thanks to @user902383 and @SeanBean.

Just like with this answer, the shortest code-golf seems to loop and print. Both recursive and
void c(int i){System.out.print(new String(new char[i]).replace("\0",i%2<1?"\\":"/"));}
seems to be longer.

Ungolfed & test code:

Try it here.

class M{
  static void c(int i){
    for(int x = 0; x++ < i;){
      System.out.print(i % 2 < 1
                        ? 92
                        : '/');
    }
  }

  public static void main(String[] a){
    for(int i = 0; i < 10; i++){
      c(i);
      System.out.println();
    }
  }
}

Output:

/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////

Java 11, 68 65 29 bytes

n->(n%2<1?"\\":"/").repeat(n)

-3 bytes saved thanks to @user902383 and @SeanBean
-36 bytes switching from Java 7 to Java 11+

Try it online.

Explanation:

n->                     // Method with integer parameter and String return-type
  (n%2<1?               //  If `n` is even:
         "\\"           //   Use String "\"
        :               //  Else (`n` is odd):
         "/")           //   Use String "/" instead
             .repeat(n) //  Repeat it `n` amount of times
Commonmark migration
Source Link

#Java 7, 68 65 bytes

Java 7, 68 65 bytes

void c(int i){for(int x=0;x++<i;)System.out.print(i%2<1?92:'/');}

3 bytes saved thanks to @user902383 and @SeanBean.

Just like with this answer, the shortest code-golf seems to loop and print. Both recursive and
void c(int i){System.out.print(new String(new char[i]).replace("\0",i%2<1?"\\":"/"));}
seems to be longer.

Ungolfed & test code:

Try it here.

class M{
  static void c(int i){
    for(int x = 0; x++ < i;){
      System.out.print(i % 2 < 1
                        ? 92
                        : '/');
    }
  }

  public static void main(String[] a){
    for(int i = 0; i < 10; i++){
      c(i);
      System.out.println();
    }
  }
}

Output:

/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////

#Java 7, 68 65 bytes

void c(int i){for(int x=0;x++<i;)System.out.print(i%2<1?92:'/');}

3 bytes saved thanks to @user902383 and @SeanBean.

Just like with this answer, the shortest code-golf seems to loop and print. Both recursive and
void c(int i){System.out.print(new String(new char[i]).replace("\0",i%2<1?"\\":"/"));}
seems to be longer.

Ungolfed & test code:

Try it here.

class M{
  static void c(int i){
    for(int x = 0; x++ < i;){
      System.out.print(i % 2 < 1
                        ? 92
                        : '/');
    }
  }

  public static void main(String[] a){
    for(int i = 0; i < 10; i++){
      c(i);
      System.out.println();
    }
  }
}

Output:

/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////

Java 7, 68 65 bytes

void c(int i){for(int x=0;x++<i;)System.out.print(i%2<1?92:'/');}

3 bytes saved thanks to @user902383 and @SeanBean.

Just like with this answer, the shortest code-golf seems to loop and print. Both recursive and
void c(int i){System.out.print(new String(new char[i]).replace("\0",i%2<1?"\\":"/"));}
seems to be longer.

Ungolfed & test code:

Try it here.

class M{
  static void c(int i){
    for(int x = 0; x++ < i;){
      System.out.print(i % 2 < 1
                        ? 92
                        : '/');
    }
  }

  public static void main(String[] a){
    for(int i = 0; i < 10; i++){
      c(i);
      System.out.println();
    }
  }
}

Output:

/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

#Java 7, 68 65 bytes

void c(int i){for(int x=0;x++<i;)System.out.print(i%2<1?92:'/');}

3 bytes saved thanks to @user902383 and @SeanBean.

Just like with this answerwith this answer, the shortest code-golf seems to loop and print. Both recursive and
void c(int i){System.out.print(new String(new char[i]).replace("\0",i%2<1?"\\":"/"));}
seems to be longer.

Ungolfed & test code:

Try it here.

class M{
  static void c(int i){
    for(int x = 0; x++ < i;){
      System.out.print(i % 2 < 1
                        ? 92
                        : '/');
    }
  }

  public static void main(String[] a){
    for(int i = 0; i < 10; i++){
      c(i);
      System.out.println();
    }
  }
}

Output:

/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////

#Java 7, 68 65 bytes

void c(int i){for(int x=0;x++<i;)System.out.print(i%2<1?92:'/');}

3 bytes saved thanks to @user902383 and @SeanBean.

Just like with this answer, the shortest code-golf seems to loop and print. Both recursive and
void c(int i){System.out.print(new String(new char[i]).replace("\0",i%2<1?"\\":"/"));}
seems to be longer.

Ungolfed & test code:

Try it here.

class M{
  static void c(int i){
    for(int x = 0; x++ < i;){
      System.out.print(i % 2 < 1
                        ? 92
                        : '/');
    }
  }

  public static void main(String[] a){
    for(int i = 0; i < 10; i++){
      c(i);
      System.out.println();
    }
  }
}

Output:

/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////

#Java 7, 68 65 bytes

void c(int i){for(int x=0;x++<i;)System.out.print(i%2<1?92:'/');}

3 bytes saved thanks to @user902383 and @SeanBean.

Just like with this answer, the shortest code-golf seems to loop and print. Both recursive and
void c(int i){System.out.print(new String(new char[i]).replace("\0",i%2<1?"\\":"/"));}
seems to be longer.

Ungolfed & test code:

Try it here.

class M{
  static void c(int i){
    for(int x = 0; x++ < i;){
      System.out.print(i % 2 < 1
                        ? 92
                        : '/');
    }
  }

  public static void main(String[] a){
    for(int i = 0; i < 10; i++){
      c(i);
      System.out.println();
    }
  }
}

Output:

/
\\
///
\\\\
/////
\\\\\\
///////
\\\\\\\\
/////////
3 bytes won
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384
Loading
added 264 characters in body
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384
Loading
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384
Loading