# Using an integer to manipulate a string/text variable

**URL:** <https://discourse.processing.org/t/using-an-integer-to-manipulate-a-string-text-variable/20015>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 22, 2020, 1:06am UTC](https://discourse.processing.org/t/using-an-integer-to-manipulate-a-string-text-variable/20015 "2020-04-22T01:06:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathanprime1](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@nathanprime1](https://discourse.processing.org/u/nathanprime1)\
**Post date:** [April 22, 2020, 1:06am UTC](https://discourse.processing.org/t/using-an-integer-to-manipulate-a-string-text-variable/20015/1 "2020-04-22T01:06:05Z")

</div>

Write a function that consumes a non-negative integer k and prints a k-size diamond. A k-size diamond consists of a top, a middle and a bottom. The middle is a single row of 2k+1 d’s. The top consists of k rows. The i throw in the top (starting from 0) contains 2i+1 d’s. The d’s on each top row are centred over the d’s on the middle row. A bottom is like a top but upside down.

Ex. k = 2;

```auto
    d
   ddd
  ddddd
   ddd
    d

```

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

```auto
int k;
int l;

void setup() {
  size(400, 400);
  k = 2;
  
  textAlign(CENTER, CENTER);
 
String s = "d";
fill(255,0,0);
text(s + s + s + s +s, CENTER + 200, CENTER + 200);  
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 22, 2020, 10:40am UTC](https://discourse.processing.org/t/using-an-integer-to-manipulate-a-string-text-variable/20015/2 "2020-04-22T10:40:15Z")

</div>

Hello and welcome to the forum!

Great to have you here!

Please note that we are not allowed to give full code solutions for homework.

- Please look in the reference at the keyword “`for`” and use a _for-loop_ with **i** as a variable (which you mentioned). Then inside the for-loop use the formula you mentioned: contains 2i+1 diamonds.

You can use `text(...., width/2, i*33);` for text output; before this say `textAlign(CENTER);`

[https://www.processing.org/reference/](https://www.processing.org/reference/)

Warm regards,

Chrisir

😉
