4 added 213 characters in body
source | link

Java 710, 114114 62 bytes

n->{var r="";for(int i=0;i++<n/9;r+=9);return(n>9?n%9:n+9)+r;}

Java and the inability to use inline-loops.. sigh >.>Try it online.

String c(int n){return""+(n>9?(n%9)+s(n):n+9);}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

EDIT: 130 bytes130 73 bytes without leading zeros (Thanks to @levanth`):

int c(int n){return Integer.parseInt(""+(n>9?(n%9)+s(n):n+9));}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}
n->{var r="";for(int i=0;i++<n/9;r+=9);return new Long((n>9?n%9:n+9)+r);}

Ungolfed & test code:Try it online.

Try it here.

class Main{
    public static void main(String[] a){
        System.out.println("2: " + c(2));
        System.out.println("8: " + c(8));
        System.out.println("12: " + c(12));
        System.out.println("16: " + c(16));
        System.out.println("18: " + c(18));
        System.out.println("24: " + c(24));
        System.out.println("32: " + c(32));
    }

    static String c(int n) {
        return "" +
            (n > 9
                ? (n % 9) + s(n)
                : n + 9);
    }

    static String s(int n) {
        String s = "";
        for (int i = 0; i < (n / 9); i++) {
            s += "9";
        }
        return s;
    }
}

OutputExplanation:

2: 11
8: 17
12: 39
16: 79
18: 099
24: 699
32: 5999

I could write something to fix the trailing 0 of the 18: 099, but I think the bytes are already high enough. ;)

n->                           // Method with integer parameter and long return-type
  var r="";                   //  Result-String, starting empty
  for(int i=0;i++<n/9;r+=9);  //  Append `n` integer-divided by 9 amount of 9's to `r`
  return new Long(            //  Cast String to number to remove any leading zeroes:
    (n>9?                     //   If the input `n` is 10 or larger
      n%9                     //    Use `n` modulo-9
     :                        //   Else (`n` is smaller than 10):
      n+9)                    //    Use `n+9`
    +r);}                     //   And append `r`

Java 7, 114 bytes

Java and the inability to use inline-loops.. sigh >.>

String c(int n){return""+(n>9?(n%9)+s(n):n+9);}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

EDIT: 130 bytes without leading zeros (Thanks to @levanth`):

int c(int n){return Integer.parseInt(""+(n>9?(n%9)+s(n):n+9));}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

Ungolfed & test code:

Try it here.

class Main{
    public static void main(String[] a){
        System.out.println("2: " + c(2));
        System.out.println("8: " + c(8));
        System.out.println("12: " + c(12));
        System.out.println("16: " + c(16));
        System.out.println("18: " + c(18));
        System.out.println("24: " + c(24));
        System.out.println("32: " + c(32));
    }

    static String c(int n) {
        return "" +
            (n > 9
                ? (n % 9) + s(n)
                : n + 9);
    }

    static String s(int n) {
        String s = "";
        for (int i = 0; i < (n / 9); i++) {
            s += "9";
        }
        return s;
    }
}

Output:

2: 11
8: 17
12: 39
16: 79
18: 099
24: 699
32: 5999

I could write something to fix the trailing 0 of the 18: 099, but I think the bytes are already high enough. ;)

Java 10, 114 62 bytes

n->{var r="";for(int i=0;i++<n/9;r+=9);return(n>9?n%9:n+9)+r;}

Try it online.

EDIT: 130 73 bytes without leading zeros (Thanks to @levanth`):

n->{var r="";for(int i=0;i++<n/9;r+=9);return new Long((n>9?n%9:n+9)+r);}

Try it online.

Explanation:

n->                           // Method with integer parameter and long return-type
  var r="";                   //  Result-String, starting empty
  for(int i=0;i++<n/9;r+=9);  //  Append `n` integer-divided by 9 amount of 9's to `r`
  return new Long(            //  Cast String to number to remove any leading zeroes:
    (n>9?                     //   If the input `n` is 10 or larger
      n%9                     //    Use `n` modulo-9
     :                        //   Else (`n` is smaller than 10):
      n+9)                    //    Use `n+9`
    +r);}                     //   And append `r`
3 deleted 14 characters in body
source | link

EDIT: 130 bytes without leading zeros (Thanks to @levanth`):

int c(int n){return Integer.parseInt(""+(n>9?(n%9)+s(n):n+9));}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

Ungolfed & test code:

I could write something to fix the trailing 0 of the 18: 099, but I think the bytes are already high enough. ;)


EDIT: 130 bytes without leading zeros (Thanks to @levanth`):

int c(int n){return Integer.parseInt(""+(n>9?(n%9)+s(n):n+9));}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

Ungolfed & test code:

I could write something to fix the trailing 0 of the 18: 099, but I think the bytes are already high enough. ;)


EDIT: 130 bytes without leading zeros (Thanks to @levanth`):

int c(int n){return Integer.parseInt(""+(n>9?(n%9)+s(n):n+9));}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

EDIT: 130 bytes without leading zeros (Thanks to @levanth`):

int c(int n){return Integer.parseInt(""+(n>9?(n%9)+s(n):n+9));}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

Ungolfed & test code:

I could write something to fix the trailing 0 of the 18: 099, but I think the bytes are already high enough. ;)

2 Added fix for leading zeros (Thanks to @levanth)
source | link

Java 7, 114 bytes

Java and the inability to use inline-loops.. sigh >.>

String c(int n){return""+(n>9?(n%9)+s(n):n+9);}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

Ungolfed & test code:

Try it here.

class Main{
    public static void main(String[] a){
        System.out.println("2: " + c(2));
        System.out.println("8: " + c(8));
        System.out.println("12: " + c(12));
        System.out.println("16: " + c(16));
        System.out.println("18: " + c(18));
        System.out.println("24: " + c(24));
        System.out.println("32: " + c(32));
    }

    static String c(int n) {
        return "" +
            (n > 9
                ? (n % 9) + s(n)
                : n + 9);
    }

    static String s(int n) {
        String s = "";
        for (int i = 0; i < (n / 9); i++) {
            s += "9";
        }
        return s;
    }
}

Output:

2: 11
8: 17
12: 39
16: 79
18: 099
24: 699
32: 5999

I could write something to fix the trailing 0 of the 18: 099, but I think the bytes are already high enough. ;)


EDIT: 130 bytes without leading zeros (Thanks to @levanth`):

int c(int n){return Integer.parseInt(""+(n>9?(n%9)+s(n):n+9));}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

Java 7, 114 bytes

Java and the inability to use inline-loops.. sigh >.>

String c(int n){return""+(n>9?(n%9)+s(n):n+9);}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

Ungolfed & test code:

Try it here.

class Main{
    public static void main(String[] a){
        System.out.println("2: " + c(2));
        System.out.println("8: " + c(8));
        System.out.println("12: " + c(12));
        System.out.println("16: " + c(16));
        System.out.println("18: " + c(18));
        System.out.println("24: " + c(24));
        System.out.println("32: " + c(32));
    }

    static String c(int n) {
        return "" +
            (n > 9
                ? (n % 9) + s(n)
                : n + 9);
    }

    static String s(int n) {
        String s = "";
        for (int i = 0; i < (n / 9); i++) {
            s += "9";
        }
        return s;
    }
}

Output:

2: 11
8: 17
12: 39
16: 79
18: 099
24: 699
32: 5999

I could write something to fix the trailing 0 of the 18: 099, but I think the bytes are already high enough. ;)

Java 7, 114 bytes

Java and the inability to use inline-loops.. sigh >.>

String c(int n){return""+(n>9?(n%9)+s(n):n+9);}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}

Ungolfed & test code:

Try it here.

class Main{
    public static void main(String[] a){
        System.out.println("2: " + c(2));
        System.out.println("8: " + c(8));
        System.out.println("12: " + c(12));
        System.out.println("16: " + c(16));
        System.out.println("18: " + c(18));
        System.out.println("24: " + c(24));
        System.out.println("32: " + c(32));
    }

    static String c(int n) {
        return "" +
            (n > 9
                ? (n % 9) + s(n)
                : n + 9);
    }

    static String s(int n) {
        String s = "";
        for (int i = 0; i < (n / 9); i++) {
            s += "9";
        }
        return s;
    }
}

Output:

2: 11
8: 17
12: 39
16: 79
18: 099
24: 699
32: 5999

I could write something to fix the trailing 0 of the 18: 099, but I think the bytes are already high enough. ;)


EDIT: 130 bytes without leading zeros (Thanks to @levanth`):

int c(int n){return Integer.parseInt(""+(n>9?(n%9)+s(n):n+9));}String s(int n){String s="";for(int i=0;i<n/9;i++)s+="9";return s;}
1
source | link