# Largest digit in an integer!

**URL:** <https://discourse.processing.org/t/largest-digit-in-an-integer/4381>\
**Category:** Beginners\
**Created:** [October 12, 2018, 6:00am UTC](https://discourse.processing.org/t/largest-digit-in-an-integer/4381 "2018-10-12T06:00:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Who](https://avatars.discourse-cdn.com/v4/letter/w/cdc98d/32.png) [@Who](https://discourse.processing.org/u/Who)\
**Post date:** [October 12, 2018, 6:00am UTC](https://discourse.processing.org/t/largest-digit-in-an-integer/4381/1 "2018-10-12T06:00:34Z")

</div>

I have the following question that I am stuck at ☹

Define a function that when passed an integer, returns the highest digit in the integer. Call the function in setup() by passing an integer of your choice and store the value returned in a variable result.

I don’t have any idea where and how to start. Could someone give me a hint please?

Thanks  
WoH

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 12, 2018, 3:53pm UTC](https://discourse.processing.org/t/largest-digit-in-an-integer/4381/2 "2018-10-12T15:53:34Z")

</div>

@Who

Why don’t you start one step at a time.

1. First, create a sketch with a setup.
2. Next, give your function a name, and call pass it an integer. It does nothing. Run it. Working?
3. Next, print that number in your function with println. Working?
4. Next, return that number to setup with the return statement. Working?
5. Ok, now you are ready to get the top digit. There are many ways to do this – including using integer division (/), or modulo(%), or converting a number to a string an manipulating the string… and more!

- [https://processing.org/reference/divide.html](https://processing.org/reference/divide.html)
- [https://processing.org/reference/modulo.html](https://processing.org/reference/modulo.html)
- [https://processing.org/reference/trim\_.html](https://processing.org/reference/trim_.html)

For feedback, please post your code and your followup question here.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [October 12, 2018, 4:15pm UTC](https://discourse.processing.org/t/largest-digit-in-an-integer/4381/3 "2018-10-12T16:15:01Z")

</div>

Sorry misread the question so my answer was way off target.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 12, 2018, 8:46pm UTC](https://discourse.processing.org/t/largest-digit-in-an-integer/4381/4 "2018-10-12T20:46:50Z")

</div>

1. [Processing.org/reference/strconvert\_.html](http://Processing.org/reference/strconvert_.html)
2. [Processing.org/reference/String\_charAt\_.html](http://Processing.org/reference/String_charAt_.html)
3. [Processing.org/reference/intconvert\_.html](http://Processing.org/reference/intconvert_.html)
