# How do i add characters in a string, i have 11 digits in my string and i am supposed to add the odd number positions

**URL:** <https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [July 11, 2021, 4:58pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174 "2021-07-11T16:58:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tay](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@Tay](https://discourse.processing.org/u/Tay)\
**Post date:** [July 11, 2021, 4:58pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/1 "2021-07-11T16:58:25Z")

</div>

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

How do i add characters in a string, i have 11 digits in my string and i am supposed to add the odd number positions

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2021, 5:06pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/2 "2021-07-11T17:06:38Z")

</div>

Hello,

There is a _tutorial_ here to help you:  
_[Tutorials \ Processing.org](https://processing.org/tutorials/)_

Take a look at the _String Functions_ in the _references_:  
_[Language Reference (API) \ Processing 3+](https://processing.org/reference/)_

`:)`

---

<div class="post-metadata">

**Author:** ![Tay](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@Tay](https://discourse.processing.org/u/Tay)\
**Post date:** [July 11, 2021, 6:18pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/3 "2021-07-11T18:18:39Z")

</div>

i did find a tutorial on displaying character by character but is it that i seperate then convert to integer then that is when i can add?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2021, 6:28pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/4 "2021-07-11T18:28:07Z")

</div>

Hello,

Look through the references.  
It is all in there.  
Then piece it together.

This is your homework exercise and research is part of that.

`:)`

---

<div class="post-metadata">

**Author:** ![Tay](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@Tay](https://discourse.processing.org/u/Tay)\
**Post date:** [July 11, 2021, 6:50pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/5 "2021-07-11T18:50:51Z")

</div>

ohhh i saw what you mean, i found how to seperate them then converting, thank you!

---

<div class="post-metadata">

**Author:** ![Tay](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@Tay](https://discourse.processing.org/u/Tay)\
**Post date:** [July 11, 2021, 6:51pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/6 "2021-07-11T18:51:27Z")

</div>

import javax.swing.JOptionPane;  
size(500,500);  
String t= JOptionPane.showInputDialog(“Enter the first 11 digits of a UPC-A code:”); //this prompts the user to enter the first 11 didgits of a UPC-A code  
char oddOne= t.charAt(0); //this is the odd-number position of 1  
int oddOneOne=int(oddOne); // converting this character to an integer  
char oddThree= t.charAt(2); //this is the odd-number position of 3  
int oddThreeThree=int(oddThree); //converting this character to an integer  
char oddFive=t.charAt(4); //this is the odd-number position of 5  
int oddFiveFive=int(oddFive); //converting this character to an interger  
char oddSeven= t.charAt(6); //this is the odd-number position of 7  
int oddSevenSeven= int(oddSeven); //converting this character to an interger  
char oddNine= t.charAt(8); //this is the odd-number position of 9  
int oddNineNine= int(oddNine); //converting this character to an integer  
char oddEleven=t.charAt(10); //this is the odd-number position of 11  
int oddElevenEleven= int(oddEleven); //converting this character to an integer  
char evenTwo=t.charAt(1);

---

<div class="post-metadata">

**Author:** ![Tay](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@Tay](https://discourse.processing.org/u/Tay)\
**Post date:** [July 11, 2021, 6:51pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/7 "2021-07-11T18:51:57Z")

</div>

this is what i have so far, im yet to add them, is it looking correct though?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2021, 10:47pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/8 "2021-07-11T22:47:00Z")

</div>

> [@Tay](#):
>
> is it looking correct though?

Please format your code as per the guidelines:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

Please read and tag all your homework questions as homework as per:  
[https://discourse.processing.org/faq#homework](https://discourse.processing.org/faq#homework)

If you are using the Processing IDE to write code you can print to the console:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9e20143feca1e17fa402169080072afc331a3ce6.png)

`53` is the correct value (decimal) for the ASCII character for `5`.

See:  
_[https://www.asciitable.com/](https://www.asciitable.com/)_

If you are converting a _char_ to an _int_ and want the _value_ the ASCII character represents you will have to add an offset to it; take a look at the ASCII value for decimal 0 and notice they are sequential so the offset is the same.

The alternative is here if you want to convert a _substring_ of a _String_ directly to an _int_:  
_[String / Reference / Processing.org](https://processing.org/reference/String.html)_

`:)`

---

<div class="post-metadata">

**Author:** ![Tay](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@Tay](https://discourse.processing.org/u/Tay)\
**Post date:** [July 11, 2021, 11:19pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/9 "2021-07-11T23:19:53Z")

</div>

oh alright, i had manged to figure it out in the end, thank you so much for your help

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 11, 2021, 11:54pm UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/10 "2021-07-11T23:54:57Z")

</div>

> [@Tay](#):
>
> i had manged to figure it out in the end, thank you so much for your help

You are welcome.

It gets easier in time!

Every step you take, success or failure, is part of the learning process and is progress.

`:)`

---

<div class="post-metadata">

**Author:** ![Tay](https://avatars.discourse-cdn.com/v4/letter/t/ecb155/32.png) [@Tay](https://discourse.processing.org/u/Tay)\
**Post date:** [July 12, 2021, 4:00am UTC](https://discourse.processing.org/t/how-do-i-add-characters-in-a-string-i-have-11-digits-in-my-string-and-i-am-supposed-to-add-the-odd-number-positions/31174/11 "2021-07-12T04:00:14Z")

</div>

i suppose you’re right, enjoy the rest of your day!
